I am using Laravel 5.2 and I have managed to set correctly my update request for my users but when I do exactly the same for another table (clusters), I cannot get the id in the clusterrequest validation.
Here is what I have for my clusters: routes:
Route::post('clusterFormUpdate/{id}', ['uses'=>'ClusterController@postFormUpdate','middleware' => ['permission:user-edit']]);
Controller:
public function postFormUpdate(ClusterUpdateRequest $request, $id)
{
$inputs = $request->all();
ClusterUpdateRequest:
...
public function rules()
{
$id = $this->id;
dd($id);
return [
'name' => 'required|max:255|unique:clusters,name,' . $id . ',id',
'countries' => 'required',
];
}
When I run this, I get null.
If I try the same for my user table, I get the id that is printed correctly so I was wondering where I can look for this problem?
Thanks.
To get the id in the Request
you can use the route()
method:
public function rules()
{
$id = $this->route('n'); //or whatever it is named in the route
return [
'name' => 'required|max:255|unique:clusters,name,' . $id . ',id',
'countries' => 'required',
];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With