Level 80
@Giorgi Just check the ID in your actual edit() action?
public function edit($id)
{
if ($id == 43) {
return redirect('/');
}
$company = Company::findOrFail($id);
return view('company.show', compact('company'));
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have route:
Route::resource('companies', 'Companies');
and I need get $id in middleware, when I use edit() function. I have try like this:
public function __construct()
{
$this->middleware(function ($request, $next) {
if ( $request->route()->parameter('id') == 43 ) return redirect('/');
return $next($request);
})->only('edit');
}
but it doesn't work. Can anyone help me?
Please or to participate in this conversation.