$this->id because the form request extends request
(assuming you passed the id in the request)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello! I have update method in EmployeesController and I want to validate the input data. So I use own StoreEmployeeRequest.
public function update(StoreEmployeeRequest $request, $id)
{
//
}
Inside StoreEmployeeRequest.php I have rules() method, where I put all rules.
public function rules()
{
return [
'surname' => 'required|max:50',
'name' => 'required|max:50',
'patronymic' => 'required|max:50',
'passport' => 'required|min:6|max:30|unique:employees,passport'
// and some more rules
];
}
passport must be unique, so this validation is OK for creating new row, BUT I need to update existing one.
I read that I need to pass third param to unique validation rule that equals to id like below:
'passport' => 'required|min:6|max:30|unique:employees,passport,' . $id
And here is the problem. How can I get id inside StoreEmployeeRequest.php?
I saw this solution: https://laracasts.com/discuss/channels/requests/laravel-5-validation-request-how-to-handle-validation-on-update/replies/4310
First variant is working (but for some reason I think that it's now a good solution):
$request->segment(2)
Are there any other solutions to get id, because the second variant from the link above isn't working :(
$request->get('id')
sorry, try $this->route('employee') as that is what you called it in the url
Please or to participate in this conversation.