Support the ongoing development of Laravel.io →
Requests Architecture Configuration
Last updated 7 months ago.
0
Solution

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.

0

thank you so much. well explained.

0

Sign in to participate in this thread!

LoadForge

Your banner here too?

arafatx arafatx Joined 16 Aug 2015

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.

© 2022 Laravel.io - All rights reserved.