54 lines
1.8 KiB
PHP
54 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Inventory;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class StoreProductionRequest extends FormRequest
|
|
{
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, mixed|string>>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'product_id' => ['required', 'integer', 'exists:products,id'],
|
|
'location_id' => ['required', 'integer', 'exists:locations,id'],
|
|
'produced_at' => ['required', 'date'],
|
|
'quantity' => ['required', 'integer', 'min:1'],
|
|
'notes' => ['nullable', 'string', 'max:2000'],
|
|
'ingredient_lines' => ['required', 'array', 'min:1'],
|
|
'ingredient_lines.*.ingredient_id' => ['required', 'integer', 'exists:ingredients,id'],
|
|
'ingredient_lines.*.stock_entry_id' => ['required', 'integer', 'exists:stock_entries,id'],
|
|
'ingredient_lines.*.quantity_used' => ['required', 'string'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function validatedPayload(): array
|
|
{
|
|
$data = $this->validated();
|
|
|
|
return [
|
|
'product_id' => (int) $data['product_id'],
|
|
'location_id' => (int) $data['location_id'],
|
|
'produced_at' => $data['produced_at'],
|
|
'quantity' => (int) $data['quantity'],
|
|
'notes' => $data['notes'] ?? null,
|
|
'ingredient_lines' => array_map(function (array $line): array {
|
|
return [
|
|
'ingredient_id' => (int) $line['ingredient_id'],
|
|
'stock_entry_id' => (int) $line['stock_entry_id'],
|
|
'quantity_used' => $line['quantity_used'],
|
|
];
|
|
}, $data['ingredient_lines']),
|
|
];
|
|
}
|
|
}
|