Erster Upload
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\SpiceSupplierResource\Pages;
|
||||
|
||||
use App\Filament\User\Resources\SpiceSupplierResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Spice;
|
||||
|
||||
class CreateSpiceSupplier extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SpiceSupplierResource::class;
|
||||
|
||||
protected function handleRecordCreation(array $data): Model {
|
||||
$record = static::getModel()::create($data);
|
||||
|
||||
Spice::findOrFail($data['spice_id'])->increment('quantity', $data['amount']);
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\SpiceSupplierResource\Pages;
|
||||
|
||||
use App\Filament\User\Resources\SpiceSupplierResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Notifications\Notification;
|
||||
use App\Models\Spice;
|
||||
|
||||
class EditSpiceSupplier extends EditRecord
|
||||
{
|
||||
protected static string $resource = SpiceSupplierResource::class;
|
||||
|
||||
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
\Filament\Actions\DeleteAction::make()->before(function ($record) {
|
||||
if (!$record->spice || $record->spice->quantity < $record->amount) {
|
||||
Notification::make()
|
||||
->warning()
|
||||
->title('Fehler!')
|
||||
->body('Nicht mehr genügend ' . htmlentities($record->spice->name) . ' im Lager (bräuchte mindestens Liefermenge um Lieferung rückgängig zu machen)')
|
||||
->send();
|
||||
$this->halt();
|
||||
return false;
|
||||
}
|
||||
Spice::findOrFail($record->spice->id)->decrement('quantity', $record->amount);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\SpiceSupplierResource\Pages;
|
||||
|
||||
use App\Filament\User\Resources\SpiceSupplierResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSpiceSuppliers extends ListRecords
|
||||
{
|
||||
protected static string $resource = SpiceSupplierResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user