user22247
0
Q:

laravel route model binding

# Using Request
Route::get('user/{name}', function (Request $request) {
    return $request->route('name');
});
4
Route::get('/menu/{category}/{product}/{item}', ['as' => 'named.route' , 'uses' => '[email protected]']);

// to get the actual linke
route('named.route', ['category' => $category->id, 'product' => $product->id, 'item' => $item->id]);
2
Route::get('user/{id}', function ($id) {
    return 'User '.$id;
});
2
Route::view('/welcome', 'welcome');

Route::view('/welcome', 'welcome', ['name' => 'Taylor']);
0
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
    //
});
0
Route::get('/novanoticia', '[email protected]')->name('route_name');
-1
Route::bind('user', function($value)
{
    return User::where('name', $value)->first();
});

// We can And Do also this in model..

/**
 * Retrieve the model for a bound value.
 *
 * @param  mixed  $value
 * @param  string|null  $field
 * @return \Illuminate\Database\Eloquent\Model|null
 */
public function resolveRouteBinding($value, $field = null)
{
    return $this->where('name', $value)->firstOrFail();
}
-1

New to Communities?

Join the community