ldc-legaulois/app/Http/Requests/UpdateRange.php
Jérémy Munsch f39f990748
npm i vue-nestable --save-dev
add subranges system
add SubRanges Component
add Subranges add on BO Product.edit
add Subrange filter on products.index
2021-09-24 00:18:02 +02:00

53 lines
1.8 KiB
PHP

<?php
namespace App\Http\Requests;
use App\Models\Products;
use App\Models\Range;
class UpdateRange extends StoreRange
{
public function authorize()
{
$this->merge([
'flagship_product' => empty($this->flagship_product) ? null : $this->flagship_product
]);
return parent::authorize();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return \array_merge(parent::rules(), [
'slug' => [
'required',
//phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
if ($this->range->slug !== $value and Range::where('slug', $value)->exists()) {
$fail("Le champ Nom est déjà utilisé");
}
}
],
'picture' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=640,height=564',
'picture_r' => 'sometimes|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1366,height=563',
'status' => 'required|boolean',
'flagship_product' => [
'nullable',
'exists:products,id',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
function ($attribute, $value, $fail) {
if (!Products::where('range_id', $value)->get()) {
$fail('Le product sélectionné n\'appartient pas à cette gamme');
}
}
],
'subranges' => 'sometimes|array|max:5',
'subranges.*' => 'int|exists:sub_ranges,id',
]);
}
}