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}