I assume you set route model binding to slug also?
Route::resource('profiles', 'ProfileController');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've been getting this error
LogicException Route pattern "/profile/{slug}/{{slug}}" cannot reference variable name "slug" more than once.
Routes
// User Profile
Route::resource('profile/{slug}', 'ProfileController');
// Vendor Profile
Route::resource('vendor-profile/{slug}', 'VendorController');
// Agent Profile
Route::resource('agent-profile/{slug}', 'AgentController');
Controller
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(User $slug)
{
return view('user.profile-index', compact('slug'));
}
In that case you have to use where
User::where('slug', $profile)->firstOrFail();
getRouteKeyName works only for route model binding
Please or to participate in this conversation.