Rework products with components

This commit is contained in:
2024-08-14 22:16:09 +10:00
parent 1b581e9feb
commit f1031beff6
11 changed files with 132 additions and 302 deletions

View File

@@ -3,7 +3,9 @@
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use App\Models\ProviderOauth;
/**
* Editing Suppliers
@@ -17,7 +19,7 @@ class ProductAddEdit extends FormRequest
*/
public function authorize()
{
return Auth::user()->isWholesaler();
return Gate::allows('wholesaler');
}
/**
@@ -34,7 +36,21 @@ class ProductAddEdit extends FormRequest
'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
'accounting' => 'nullable|array', // @todo Validate that the value is in the accounting system
'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
}
},
],
'pricing' => 'required|array', // @todo Validate the elements in the pricing
];
}