@Tenzing remove this line from your RouteServiceProvider and it should work:
$router->model('consumers', 'App\Consumer');
Usman.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying use a provided email address to fetch a record and pass it to the edit view. I can do this with out issue using the id but can't with any other db values. From what i am understanding this is because the route resource default key is id. However, I thought this could be overridden using route model binding.
Here is my route.php
Route::bind('consumers', function($email) { return App\Consumer::where('email', $email)->first(); }); Route::resource('consumers', 'ConsumersController'); Route::get('consumers/{consumers}', 'ConsumersController@show');
and my Controller
public function show(Consumer $email)
{
return view('consumers.edit', compact('consumer'));
}
In my RouterServiceProvider I have also added
$router->model('consumers', 'App\Consumer');
When I try this in the browser:
/consumers/edward.hunter@test.com
I get a NotFoundHttpException in Router.php line 927
I have tried this with other db fields like firstName thinking that the special characters in the email might be the cause. Nope, same result.
What am I missing?? Thanks!
Please or to participate in this conversation.