In my project I do validation via the request classes. Here is one of the problematic classes:
<?php namespace App\Modules\Store\Validation\Resources\AttributeValue;
use App\Modules\Base\Services\Normalization;
use Illuminate\Foundation\Http\FormRequest;
class UpdateRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'normal' => (
'required|string|max:255|' .
'unique:attributes,normal,' . $this->value .
',id,store_id,' . $this->user()->store_id
),
'title' => 'required|string|max:255',
'value' => 'required|string|max:255',
'reference' => 'sometimes|nullable|string|max:255',
];
}
/**
* Authorization is in the policies
*
* @return bool
*/
public function authorize()
{
return true;
}
protected function prepareForValidation()
{
$this->merge([
'normal' => Normalization::lowerCaseEnglishAlphaNum($this->normal),
]);
}
}
Here is the output of php artisan route:list for the route that uses this validation class:
| | PUT|PATCH | store/attribute/{attribute}/value/{value} | Store::attribute.value.update | App\Modules\Store\Controllers\StoreAttributeValueController@update | web,auth:store,Closure |
As you can see the name of the route parameter is the same as the name of one of the form parameters. This causes an issue in the unique rule for normal since the form parameter value overwrites the route parameter value.
I would rather not have to change the names of the parameters as they are fairly descriptive. Instead I would like to be able to specify that I want the route parameter and not the form parameter.
So how do I get only the route parameter(s) from the Request object?