laravel validation attribute of array translate code example
Example 1: laravel image validation
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
Example 2: laravel request validation rules for create and update
public function rules()
{
$rules = [
'name' => 'required|string|unique:products|max:255',
];
if (in_array($this->method(), ['PUT', 'PATCH'])) {
$product = $this->route()->parameter('product');
$rules['name'] = [
'required',
'string',
'max:255',
Rule::unique('loan_products')->ignore($product),
];
}
return $rules;
}