They are for different purposes.
Route::model
is for route model bindings. You can bind a route parameter, user
to a model App\User
.
Route::model('user', 'App\User');
Route::get('user/{user}', function ($user) {
// $user is of type App\User
});
For routes that have the route parameter user
, the Model will try to be resolved based on the value of that route parameter. Instead of receiving the parameter value in your controller method you will end up with a User model being passed.
Route::resource
is for registering your resource routes for you. You could define your routes explicitly to do the same thing. The router is using the 'name' of the resource as the route parameter name (wildcard).
The way these work together is just based upon what the parameter ends up being in your route definitions. Route::resource('user', 'UserController');
will give you routes with the route parameter {user}
in it. Since we bound user
to App\User
, yoursite.com/user/1
would resolve a User with id of 1 and bind that to the route.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community