Try this
<form action="{{ route('company.index', $company) }}" method="get">
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
articles table
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->string('title');
$table->string('slug');
$table->string('image')->nullable();
$table->text('body');
$table->timestamps();
});
}
companies table
public function up()
{
Schema::create('companies', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
$table->foreignId('unity_id')->constrained()->cascadeOnDelete();
$table->foreignId('article_id')->constrained()->cascadeOnDelete();
$table->string('title');
$table->string('slug');
$table->string('image')->nullable();
$table->text('body');
$table->timestamps();
});
}
Company.php
use HasFactory, Sluggable;
protected $guarded = [];
public function user()
{
return $this->belongsTo(User::class);
}
public function unity()
{
return $this->belongsTo(Unity::class);
}
public function sluggable(): array
{
return [
'slug' => [
'source' => 'title'
]
];
}
public function path()
{
return '/company/'.$this->slug;
}
Article.php
use HasFactory, Sluggable;
protected $guarded = [];
public function user()
{
return $this->belongsTo(User::class);
}
public function sluggable(): array
{
return [
'slug' => [
'source' => 'title'
]
];
}
public function path()
{
return '/article/'.$this->slug;
}
ArticleController.php
public function single(Article $article)
{
$cities = City::query()->where('state_id', 26)->get();
return view('Home.contents.article', compact('article', 'cities'));
}
CompanyController.php
public function single(Company $company)
{
//$company = Company::query()->where('');
return view('Home.contents.company', compact('company'));
}
article.blade.php
<div class="container bg-white pt-5 pb-5">
<div class="row">
<h2>{{ $article->title }}</h2>
<div class="d-flex justify-content-center p-5">
<img src="{{ asset('storage/'.$article->image) }}" alt="{{ $article->title }}" class="img-fluid">
</div>
<div class="ps-5 pe-5 mb-3">
{{ $article->body }}
</div>
<div class="ps-5 pe-5">
<form action="{{ route('company.index') }}" method="get">
<div class="row mb-3">
<div class="col-lg-3">
<label for="city_id" class="form-label">city_id</label>
<select class="form-select" id="city_id" name="city_id">
@foreach($cities as $city)
<option value="{{ $city->id }}">{{ $city->name }}</option>
@endforeach
</select>
</div>
<div class="col-lg-3">
<label for="company_id" class="form-label">company_id</label>
<select class="form-select" id="company_id" name="company_id">
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-lg-3">
<button type="submit" class="btn btn-warning btn-lg">Continue</button>
</div>
</div>
</form>
</div>
</div>
</div>
company.blade.php
<div class="container bg-white pt-5 pb-5">
<div class="row">
<h2>{{ $company->title }}</h2>
<div class="d-flex justify-content-center p-5">
<img src="{{ asset('storage/'.$company->image) }}" alt="{{ $company->title }}" class="img-fluid">
</div>
<div class="ps-5 pe-5 mb-3">
{{ $company->body }}
</div>
</div>
</div>
web.php
Route::get('/article/{articleSlug}', [App\Http\Controllers\ArticleController::class, 'single']);
Route::get('/company/{companySlug}', [App\Http\Controllers\CompanyController::class, 'single'])->name('company.index');
RouteServiceProvider.php
Route::bind('companySlug', function ($value) {
return Company::whereSlug($value)->firstOrFail();
});
Route::bind('articleSlug', function ($value) {
return Article::whereSlug($value)->firstOrFail();
});
Ok, so now that your aren't using the company slug in the url, you can't use route model binding to get the Company model in your controller. You will have to get the model from the database yourself
$company = Company::where('id', request()->company_id)->first();
Please or to participate in this conversation.