1 public function rules()
2 {
3 $rules = [
4 'name' => 'required|string|unique:products|max:255',
5 ];
6
7 if (in_array($this->method(), ['PUT', 'PATCH'])) {
8 $product = $this->route()->parameter('product');
9
10 $rules['name'] = [
11 'required',
12 'string',
13 'max:255',
14 Rule::unique('loan_products')->ignore($product),
15 ];
16 }
17
18 return $rules;
19 }