1Route::get('/menu/{category}/{product}/{item}', ['as' => 'named.route' , 'uses' => 'MenuController@listItem']);
2
3// to get the actual linke
4route('named.route', ['category' => $category->id, 'product' => $product->id, 'item' => $item->id]);
1// In RouteServiceProvider
2 public function boot()
3 {
4 //don't forget import model at the top
5 Route::model('unique_key', Blog::class);
6 Route::bind('unique_key', function ($value) {
7 return Blog::findOrFail($value);
8 //return Blog::where('something', $value)->firstOrFail();
9 });
10
11 //default laravel codes
12 }
1Route::view('/welcome', 'welcome');
2
3Route::view('/welcome', 'welcome', ['name' => 'Taylor']);
1/**
2 * Retrieve the model for a bound value.
3 *
4 * @param mixed $value
5 * @param string|null $field
6 * @return \Illuminate\Database\Eloquent\Model|null
7 */
8public function resolveRouteBinding($value, $field = null)
9{
10 return $this->where('name', $value)->firstOrFail();
11}
1Route::bind('user', function($value)
2{
3 return User::where('name', $value)->first();
4});
5
6// We can And Do also this in model..
7
8/**
9 * Retrieve the model for a bound value.
10 *
11 * @param mixed $value
12 * @param string|null $field
13 * @return \Illuminate\Database\Eloquent\Model|null
14 */
15public function resolveRouteBinding($value, $field = null)
16{
17 return $this->where('name', $value)->firstOrFail();
18}