Laravel: Access Model instance in Form Request when using Route/Model binding

You can simply access it using the binding key, so for example if you bind Brand model: $router->model('brand', '\App\Brand') you can get instance of your model with $this->brand. Here is validation rules example:

'slug' => 'required|unique:brand,slug,' . $this->brand->id,

EDIT

Sometimes you might have an input name that uses the same name as the binding key, for example, if you bind Address model as address then you have an input field address it will make Laravel confuse. For this situation you can use route() method.

'address' => 'required|unique:addresses,address,' . $this->route('address')->id,

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)