Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

To me it sounds like you need to bind your Eloquent model to the $id passed through the URL. You can do that by inserting it into the boot() method inside your App\Providers\RouteServiceProvider. It would look something like this:

public function boot(Router $router)
{

    parent::boot($router);

    $router->bind('mymodel', function($id)
    {
        return MyModel::findOrFail($id);
    });

}

This can also go into your routes file with something like this:

Route::bind('mymodel', bind('mymodel', function($id)
 {
      return MyModel::findOrFail($id);
 });

there are a couple other places as well but the nice thing is it's really your choice.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

dyyylan dyyylan Joined 26 Dec 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.