70 lines
2.5 KiB
PHP
70 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use App\Models\Range;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdateProductRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth()->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'name' => 'required|unique:products,name,' . $this->product->id . '|min:10|max:255',
|
|
'seo_title' => 'required|max:255',
|
|
'seo_description' => 'required|max:255',
|
|
// phpcs:ignore Generic.Files.LineLength.TooLong
|
|
'picture' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=328,height=324',
|
|
'tags' => 'max:255',
|
|
'subtitle' => 'required|max:255',
|
|
'info1' => 'max:255',
|
|
'info2' => 'max:255',
|
|
'description' => 'max:255',
|
|
'type_portion' => 'max:255',
|
|
'theoretical_average_weight' => 'max:255',
|
|
'other_format' => 'max:255',
|
|
'preparation_advice' => 'max:2000',
|
|
'ingredients' => 'max:2000',
|
|
'tips' => 'max:2000',
|
|
'video_link' => 'max:255',
|
|
'range_id' => 'required|int|exists:ranges,id',
|
|
'sub_range_id' => [
|
|
'sometimes', 'nullable', 'exists:sub_ranges,id',
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
$range = Range::findOrFail($this->range_id);
|
|
if (!Range::findOrFail($this->range_id)->subranges()->pluck('id')->contains($value)) {
|
|
$fail("La sous gamme choisie n'existe pas dans la gamme $range->name");
|
|
}
|
|
}
|
|
],
|
|
'picture_video' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=328,height=324',
|
|
|
|
// Inco Values
|
|
'energy' => 'required|numeric',
|
|
'energy_kj' => 'required|numeric',
|
|
'protein' => 'required|numeric',
|
|
'carbohydrates' => 'required|numeric',
|
|
'sugar' => 'required|numeric',
|
|
'fat' => 'required|numeric',
|
|
'saturated_fatty_acids' => 'required|numeric',
|
|
'dietary_fiber' => 'required|numeric',
|
|
'salt' => 'required|numeric',
|
|
];
|
|
}
|
|
}
|