lundi 26 octobre 2015

Laravel Route Model Binding to Route::controller()

I've got the following routes:

Route::controllers([
    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
    'admin' => 'AdminController',
    'site' => 'SiteController'
]);

And then I've got the following method in the SiteController:

/**
 * Get site details and pass to view
 *
 * @param Site $site
 * @return mixed
 * @internal param $site_id
 */
public function getDetails( Site $site )
{
    return $site;
}

When I go to the URL http://ift.tt/1Wf2btK it doesn't return the site object.

I've added $router->model( 'one', 'App\Site' ); into the RouteServiceProvider and it works, but what if later down the road I want to add another controller like this but use it for jobs, and use the getDetails method again and pass through the App\Job object? It will automatically send the App\Site model instead.

So is there a way I can prevent this from happening?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire