2022-08-20 13:35:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2024-08-14 12:16:09 +00:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
use App\Models\ProviderOauth;
|
2022-08-20 13:35:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Editing Suppliers
|
|
|
|
*/
|
|
|
|
class ProductAddEdit extends FormRequest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
2024-08-14 12:16:09 +00:00
|
|
|
return Gate::allows('wholesaler');
|
2022-08-20 13:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
*
|
|
|
|
* @return array<string, mixed>
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
2022-10-18 12:23:45 +00:00
|
|
|
'translate.name_short' => 'required|string|min:2|max:100',
|
|
|
|
'translate.name_detail' => 'required|string|min:2|max:100',
|
2023-05-10 03:59:42 +00:00
|
|
|
'translate.description' => 'required|string|min:2|max:65535',
|
2022-08-20 13:35:41 +00:00
|
|
|
'active' => 'sometimes|accepted',
|
|
|
|
'model' => 'sometimes|string', // @todo Check that it is a valid model type
|
|
|
|
'model_id' => 'sometimes|int', // @todo Check that it is a valid model type
|
2024-08-14 12:16:09 +00:00
|
|
|
'accounting' => [
|
|
|
|
'nullable',
|
|
|
|
'array',
|
|
|
|
function (string $attribute,mixed $value,\Closure $fail) {
|
|
|
|
if (! is_array($value))
|
|
|
|
$fail("Invalid format for {$attribute}");
|
|
|
|
|
|
|
|
foreach ($value as $k=>$v) {
|
|
|
|
if (! ProviderOauth::where('id',$k)->exists())
|
|
|
|
$fail("Provider doesnt exist [$k]");
|
|
|
|
|
|
|
|
// @todo Validate that the value is in the accounting system
|
|
|
|
}
|
|
|
|
},
|
|
|
|
],
|
2023-05-04 12:17:42 +00:00
|
|
|
'pricing' => 'required|array', // @todo Validate the elements in the pricing
|
2022-08-20 13:35:41 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|