mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-10-27 00:37:14 +01:00
Updated IReserved Item: Model, Resource, Migration
This commit is contained in:
parent
eaf954d7ff
commit
2aff888fd0
7 changed files with 45 additions and 49 deletions
|
|
@ -9,11 +9,14 @@ use App\Models\Item;
|
|||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Get;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
|
||||
|
||||
class ReserveditemResource extends Resource
|
||||
|
|
@ -22,7 +25,7 @@ class ReserveditemResource extends Resource
|
|||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-archive-box-x-mark';
|
||||
|
||||
protected static ?string $modelLabel = 'Reserved items';
|
||||
protected static ?string $modelLabel = 'Reservations';
|
||||
|
||||
protected static ?string $title = 'Reserve an item';
|
||||
|
||||
|
|
@ -30,21 +33,12 @@ class ReserveditemResource extends Resource
|
|||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('item_id')
|
||||
->label('Choose item to reserve')
|
||||
->relationship(
|
||||
name: 'item',
|
||||
titleAttribute: 'desc',
|
||||
modifyQueryUsing: fn ($query) => $query->where('can_be_loaned', true)->where('reserved', false)
|
||||
)
|
||||
->required()
|
||||
->disabledOn('edit')
|
||||
->hiddenOn('edit'),
|
||||
//Forms\Components\TextInput::make('user_id')
|
||||
// ->label('Användare')
|
||||
// ->default(auth()->id())
|
||||
// ->disabledOn(['edit', 'create'])
|
||||
// ->hiddenOn('edit'),
|
||||
Forms\Components\TextInput::make('username')
|
||||
->label('Name')
|
||||
->default(null),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->label('Email')
|
||||
->default(null),
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Toggle::make('delivered'),
|
||||
|
|
@ -65,6 +59,9 @@ class ReserveditemResource extends Resource
|
|||
Tables\Columns\TextColumn::make('username')
|
||||
->label('User')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('email')
|
||||
->label('Email')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('reserved_date')
|
||||
->label('Reservation date')
|
||||
->sortable(),
|
||||
|
|
@ -82,12 +79,15 @@ class ReserveditemResource extends Resource
|
|||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\EditAction::make()
|
||||
->button()
|
||||
->icon('heroicon-m-pencil-square')
|
||||
->iconPosition(IconPosition::After),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
// Tables\Actions\BulkActionGroup::make([
|
||||
// Tables\Actions\DeleteBulkAction::make(),
|
||||
// ]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -107,12 +107,13 @@ class ReserveditemResource extends Resource
|
|||
];
|
||||
}
|
||||
|
||||
public static function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
ItemResource\Widgets\ItemsOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@ class CreateReserveditem extends CreateRecord
|
|||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
if(!$data['username']) {
|
||||
$data['user_id'] = auth()->id();
|
||||
$data['username'] = auth()->user()->name;
|
||||
$data['email'] = auth()->user()->email;
|
||||
}
|
||||
$data['reserved_date'] = Carbon::now();
|
||||
|
||||
if ($data['delivered'])
|
||||
|
|
@ -49,10 +52,5 @@ class CreateReserveditem extends CreateRecord
|
|||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function getFooterWidgets(): array
|
||||
{
|
||||
return [
|
||||
ItemResource\Widgets\ItemsOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class EditReserveditem extends EditRecord
|
|||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
//Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -51,4 +51,9 @@ class EditReserveditem extends EditRecord
|
|||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Edit: ' . Item::where('id', $this->getRecord()->item_id)->pluck('desc')->first();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,12 +94,7 @@ class ReserveditemResourceUser extends Resource
|
|||
];
|
||||
}
|
||||
|
||||
public static function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
ItemResource\Widgets\ItemsOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
|
|
|
|||
|
|
@ -42,10 +42,5 @@ class CreateReserveditemUser extends CreateRecord
|
|||
Item::where('id', $record->item_id)->update(['reserved' => true]);
|
||||
}
|
||||
|
||||
protected function getFooterWidgets(): array
|
||||
{
|
||||
return [
|
||||
ItemResource\Widgets\ItemsOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ class Reserveditem extends Model
|
|||
'delivered',
|
||||
'returned',
|
||||
'user_id',
|
||||
'item_id'
|
||||
'item_id',
|
||||
'email'
|
||||
];
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ return new class extends Migration
|
|||
$table->foreignId('item_id')->constrained('items')->cascadeOnDelete();
|
||||
$table->integer('user_id')->nullable();
|
||||
$table->string('username')->nullable();
|
||||
$table->string('email')->nullable();
|
||||
$table->timestamp('reserved_date')->nullable();
|
||||
$table->timestamp('delivered_date')->nullable();
|
||||
$table->timestamp('return_date')->nullable();
|
||||
|
|
|
|||
Loading…
Reference in a new issue