I created a validation for the creation and editing forms using Laravel's Request.
But I use the same form for creating and editing. So I created an exception so that when the url id is equal to the id registered in the database, it is allowed to insert the field that is configured as unique.
As you can see I'm using the segment to get the id that is being edited from the url, but it always returns null
public function rules()
{
$id = $this->segment(3);
return [
'name' => "required|min:3|max:255|unique:companies,name,{$id},id",
'image' => 'nullable|min:3|max:255',
];
}
How can I get this id from the url? what am I doing wrong? In the Laravel 6 version I used the same method to get the id and I had no problems
You may try: