mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-10-26 21:37:14 +01:00
Compare commits
7 commits
daca1c7886
...
521a70f9a1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
521a70f9a1 | ||
|
|
9fabd16e40 | ||
|
|
2aff888fd0 | ||
|
|
eaf954d7ff | ||
|
|
5ee8c3c865 | ||
|
|
43e60914a7 | ||
|
|
0db7047403 |
26 changed files with 425 additions and 203 deletions
124
app/Filament/Pages/Reserve.php
Normal file
124
app/Filament/Pages/Reserve.php
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\BasePage;
|
||||
use App\Filament\Widgets\StatsOverviewWidget;
|
||||
use App\Filament\Resources\ItemResource\Pages;
|
||||
use App\Filament\Resources\ItemResource\RelationManagers;
|
||||
use App\Models\Item;
|
||||
use App\Models\User;
|
||||
use App\Models\Category;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Actions\CreateAction;
|
||||
use App\Models\Reserveditem;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Infolists\Components\Section;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
|
||||
class Reserve extends BasePage implements HasTable
|
||||
{
|
||||
use InteractsWithTable;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.reserve';
|
||||
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query( Item::where('can_be_loaned', true)->where('type', "game"))
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('desc')
|
||||
->label('Description')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\ImageColumn::make('image')
|
||||
->label('Image'),
|
||||
Tables\Columns\TextColumn::make('players')
|
||||
->label('Players')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('play_time')
|
||||
->label('Play Time')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('age')
|
||||
->label('Age')
|
||||
->sortable(),
|
||||
Tables\Columns\IconColumn::make('reserved')
|
||||
->label('Available')
|
||||
->falseIcon('heroicon-o-check-badge')
|
||||
->trueIcon('heroicon-o-x-mark')
|
||||
->falseColor('success')
|
||||
->trueColor('danger')
|
||||
->default(false),
|
||||
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('category_id')
|
||||
->label('Category')
|
||||
->multiple()
|
||||
->options(Category::all()->where('type', 'game')->pluck('name', 'id')),
|
||||
Filter::make('reserved')
|
||||
->label('Available')
|
||||
->query(fn (Builder $query): Builder => $query->where('reserved', false))
|
||||
->columnSpanFull()
|
||||
->toggle()
|
||||
],layout: FiltersLayout::AboveContent)
|
||||
->actions([
|
||||
Tables\Actions\Action::make('More info')
|
||||
->modalSubmitAction(false)
|
||||
->infolist([
|
||||
Section::make('Game')
|
||||
->schema([
|
||||
TextEntry::make('desc'),
|
||||
TextEntry::make('acquisition_date'),
|
||||
TextEntry::make('category.name'),
|
||||
TextEntry::make('players'),
|
||||
TextEntry::make('play_time'),
|
||||
TextEntry::make('age'),
|
||||
])
|
||||
->columns(),
|
||||
]),
|
||||
Tables\Actions\Action::make('reserve')
|
||||
->label('Reserve')
|
||||
->button()
|
||||
->color('success')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('username')
|
||||
->label('Name')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->label('Email')
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data, Item $record): void {
|
||||
Reserveditem::create([
|
||||
'item_id' => $record->id,
|
||||
'reserved_date' => Carbon::now(),
|
||||
'username' => $data['username'],
|
||||
'email' => $data['email']
|
||||
]);
|
||||
Item::where('id', $record->id)->update(['reserved' => true]);
|
||||
})
|
||||
->hidden(fn ($record) => $record->reserved)
|
||||
])
|
||||
->bulkActions([
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\TypeResource\Pages;
|
||||
use App\Filament\Resources\TypeResource\RelationManagers;
|
||||
use App\Models\Type;
|
||||
use App\Filament\Resources\CategoryResource\Pages;
|
||||
use App\Filament\Resources\CategoryResource\RelationManagers;
|
||||
use App\Models\Category;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
|
|
@ -13,23 +13,29 @@ use Filament\Tables\Table;
|
|||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TypeResource extends Resource
|
||||
class CategoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Type::class;
|
||||
protected static ?string $model = Category::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-bookmark';
|
||||
|
||||
protected static ?string $modelLabel = 'Item types';
|
||||
protected static ?string $modelLabel = 'Categories';
|
||||
|
||||
protected static ?string $title = 'Item Types';
|
||||
protected static ?string $title = 'Categories';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\Select::make('type')
|
||||
->required()
|
||||
->options([
|
||||
'game' => 'Game',
|
||||
'item' => 'Item',
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +46,9 @@ class TypeResource extends Resource
|
|||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Name')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label('Type')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
|
|
@ -64,9 +73,9 @@ class TypeResource extends Resource
|
|||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListTypes::route('/'),
|
||||
'create' => Pages\CreateType::route('/create'),
|
||||
'edit' => Pages\EditType::route('/{record}/edit'),
|
||||
'index' => Pages\ListCategories::route('/'),
|
||||
'create' => Pages\CreateCategory::route('/create'),
|
||||
'edit' => Pages\EditCategory::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
namespace App\Filament\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use App\Filament\Resources\CategoryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateType extends CreateRecord
|
||||
class CreateCategory extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
namespace App\Filament\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use App\Filament\Resources\CategoryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditType extends EditRecord
|
||||
class EditCategory extends EditRecord
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
namespace App\Filament\Resources\CategoryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use App\Filament\Resources\CategoryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTypes extends ListRecords
|
||||
class ListCategories extends ListRecords
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
protected static string $resource = CategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
|
|
@ -6,7 +6,7 @@ use App\Filament\Resources\ItemResource\Pages;
|
|||
use App\Filament\Resources\ItemResource\RelationManagers;
|
||||
use App\Models\Item;
|
||||
use App\Models\User;
|
||||
use App\Models\Type;
|
||||
use App\Models\Category;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
|
|
@ -15,6 +15,17 @@ use Filament\Tables\Table;
|
|||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Actions\CreateAction;
|
||||
use App\Models\Reserveditem;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Support\Enums\IconPosition;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Infolists\Components\Section;
|
||||
|
||||
|
||||
class ItemResource extends Resource
|
||||
|
|
@ -23,13 +34,21 @@ class ItemResource extends Resource
|
|||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-archive-box';
|
||||
|
||||
protected static ?string $modelLabel = 'Items';
|
||||
protected static ?string $modelLabel = 'Inventory';
|
||||
|
||||
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Radio::make('type')
|
||||
->options([
|
||||
'game' => 'Game',
|
||||
'item' => 'Item',
|
||||
])
|
||||
->default('game')
|
||||
->live(),
|
||||
Forms\Components\FileUpload::make('image')
|
||||
->label('Image')
|
||||
->minSize(25)
|
||||
|
|
@ -48,16 +67,32 @@ class ItemResource extends Resource
|
|||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(1000)
|
||||
->default(0),
|
||||
Forms\Components\Select::make('type_id')
|
||||
->label('Type')
|
||||
->options(Type::all()->pluck('name', 'id'))
|
||||
->required(),
|
||||
->default(0)
|
||||
->hidden(fn ($get): string => $get('type') == 'game'),
|
||||
Forms\Components\Select::make('category_id')
|
||||
->label('Category')
|
||||
->options(Category::all()->pluck('name', 'id')),
|
||||
Forms\Components\TextInput::make('cost')
|
||||
->label('Price')
|
||||
->default(null),
|
||||
Forms\Components\TextInput::make('age')
|
||||
->label('Age')
|
||||
->maxLength(255)
|
||||
->default(null)
|
||||
->hidden(fn ($get): string => $get('type') == 'item'),
|
||||
Forms\Components\TextInput::make('players')
|
||||
->label('Players')
|
||||
->maxLength(255)
|
||||
->default(null)
|
||||
->hidden(fn ($get): string => $get('type') == 'item'),
|
||||
Forms\Components\TextInput::make('play_time')
|
||||
->label('Play time')
|
||||
->maxLength(255)
|
||||
->default(null)
|
||||
->hidden(fn ($get): string => $get('type') == 'item'),
|
||||
Forms\Components\Toggle::make('can_be_loaned')
|
||||
->label('Can be loaned'),
|
||||
->label('Can be loaned')
|
||||
->hidden(fn ($get): string => $get('type') == 'game'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -67,42 +102,111 @@ class ItemResource extends Resource
|
|||
->columns([
|
||||
Tables\Columns\TextColumn::make('desc')
|
||||
->label('Description')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('acquisition_date')
|
||||
->label('Acquisition date')
|
||||
->date()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('quantity')
|
||||
->label('Quantity')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('type.name')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label('Type')
|
||||
->numeric()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('cost')
|
||||
->label('Price')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\ImageColumn::make('image')
|
||||
->label('Image'),
|
||||
Tables\Columns\IconColumn::make('can_be_loaned')
|
||||
->label('Can be loaned')
|
||||
->sortable()
|
||||
->trueIcon('heroicon-o-check-badge')
|
||||
->falseIcon('heroicon-o-x-mark')
|
||||
->trueColor('success')
|
||||
->falseColor('danger'),
|
||||
//Tables\Columns\TextColumn::make('reserveditems.reserved')
|
||||
// ->label('Ska returneras'),
|
||||
//Tables\Columns\TextColumn::make('reserveditems.name')
|
||||
// ->label('Utlånad till')
|
||||
|
||||
Tables\Columns\IconColumn::make('reserved')
|
||||
->label('Available')
|
||||
->falseIcon('heroicon-o-check-badge')
|
||||
->trueIcon('heroicon-o-x-mark')
|
||||
->falseColor('success')
|
||||
->trueColor('danger')
|
||||
->default(false),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
SelectFilter::make('type')
|
||||
->multiple()
|
||||
->options([
|
||||
'game' => 'Game',
|
||||
'item' => 'Item',
|
||||
]),
|
||||
SelectFilter::make('category_id')
|
||||
->label('Item Category')
|
||||
->multiple()
|
||||
->options(Category::all()->where('type', 'item')->pluck('name', 'id')),
|
||||
SelectFilter::make('category_id')
|
||||
->label('Category')
|
||||
->multiple()
|
||||
->options(
|
||||
Category::all()->pluck('name', 'id'),
|
||||
),
|
||||
Filter::make('reserved')
|
||||
->label('Available')
|
||||
->query(fn (Builder $query): Builder => $query->where('reserved', false))
|
||||
->columnSpanFull()
|
||||
->toggle(),
|
||||
Filter::make('can_be_loaned')
|
||||
->label('Can be loaned')
|
||||
->query(fn (Builder $query): Builder => $query->where('can_be_loaned', true))
|
||||
->columnSpanFull()
|
||||
->toggle()
|
||||
],layout: FiltersLayout::AboveContent)
|
||||
->actions([
|
||||
Tables\Actions\Action::make('More info')
|
||||
->modalSubmitAction(false)
|
||||
->infolist([
|
||||
Section::make('Game')
|
||||
->schema([
|
||||
TextEntry::make('desc'),
|
||||
TextEntry::make('acquisition_date'),
|
||||
TextEntry::make('category.name'),
|
||||
TextEntry::make('players'),
|
||||
TextEntry::make('play_time'),
|
||||
TextEntry::make('age'),
|
||||
TextEntry::make('cost'),
|
||||
])
|
||||
->columns()
|
||||
->hidden(fn ($record) => $record->type === "item"),
|
||||
Section::make('Item')
|
||||
->schema([
|
||||
TextEntry::make('desc'),
|
||||
TextEntry::make('acquisition_date'),
|
||||
TextEntry::make('category.name'),
|
||||
TextEntry::make('quantity'),
|
||||
TextEntry::make('cost'),
|
||||
])
|
||||
->columns()
|
||||
->hidden(fn ($record) => $record->type === "game"),
|
||||
]),
|
||||
|
||||
Tables\Actions\EditAction::make()
|
||||
->button()
|
||||
->icon('heroicon-m-pencil-square')
|
||||
->iconPosition(IconPosition::After),
|
||||
Tables\Actions\Action::make('reserve')
|
||||
->label('Reserve')
|
||||
->button()
|
||||
->color('success')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('username')
|
||||
->label('Name')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->label('Email')
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data, Item $record): void {
|
||||
Reserveditem::create([
|
||||
'item_id' => $record->id,
|
||||
'reserved_date' => Carbon::now(),
|
||||
'username' => $data['username'],
|
||||
'email' => $data['email']
|
||||
]);
|
||||
Item::where('id', $record->id)->update(['reserved' => true]);
|
||||
})
|
||||
->hidden(fn ($record) => $record->reserved)
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Filament\Resources\ItemResource\Pages;
|
|||
use App\Filament\Resources\ItemResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CreateItem extends CreateRecord
|
||||
{
|
||||
|
|
@ -14,4 +15,16 @@ class CreateItem extends CreateRecord
|
|||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
|
||||
if ($data['type'] == "game")
|
||||
{
|
||||
$data['can_be_loaned'] = true;
|
||||
}
|
||||
|
||||
|
||||
return static::getModel()::create($data);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,13 @@ class EditItem extends EditRecord
|
|||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Edit: ' . $this->getRecord()->desc;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ItemResource\Widgets;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\Item;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use App\Models\Post;
|
||||
use Filament\Tables\Actions\Action;
|
||||
|
||||
class ItemsOverview extends BaseWidget
|
||||
{
|
||||
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(
|
||||
Item::where('can_be_loaned', true)
|
||||
)
|
||||
->heading('Items for lending')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('desc')
|
||||
->label('Description')
|
||||
->searchable(),
|
||||
Tables\Columns\ImageColumn::make('image')
|
||||
->label('Image'),
|
||||
Tables\Columns\IconColumn::make('reserved')
|
||||
->label('Available')
|
||||
->falseIcon('heroicon-o-check-badge')
|
||||
->trueIcon('heroicon-o-x-mark')
|
||||
->falseColor('success')
|
||||
->trueColor('danger')
|
||||
->default(false),
|
||||
Tables\Columns\TextColumn::make('reserveditem.return_date')
|
||||
->label('Available again')
|
||||
->searchable(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -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,9 +18,12 @@ class CreateReserveditem extends CreateRecord
|
|||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
$data['user_id'] = auth()->id();
|
||||
$data['username'] = auth()->user()->name;
|
||||
$data['reserved_date'] = Carbon::now();
|
||||
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,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\TableWidget as BaseWidget;
|
||||
use App\Models\Reserveditem;
|
||||
use App\Filament\Widgets\Filament;
|
||||
use Filament\Forms\Components\TextColumn;
|
||||
|
||||
class ReserveditemsOverview extends BaseWidget
|
||||
{
|
||||
protected int | string | array $columnSpan = 'full';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(
|
||||
Reserveditem::where('user_id', auth()->id())->where('returned', false)
|
||||
)
|
||||
->heading('Your reserved items')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('item.desc')
|
||||
->label('Description')
|
||||
->searchable(),
|
||||
Tables\Columns\ImageColumn::make('item.image')
|
||||
->label('Image'),
|
||||
Tables\Columns\TextColumn::make('reserved_date')
|
||||
->label('Reserved date')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('return_date')
|
||||
->label('Return date')
|
||||
->sortable(),
|
||||
Tables\Columns\IconColumn::make('delivered')
|
||||
->label('Delivered')
|
||||
->trueIcon('heroicon-o-check-badge')
|
||||
->falseIcon('heroicon-o-x-mark')
|
||||
->trueColor('success')
|
||||
->falseColor('danger'),
|
||||
Tables\Columns\IconColumn::make('returned')
|
||||
->label('Returned')
|
||||
->trueIcon('heroicon-o-check-badge')
|
||||
->falseIcon('heroicon-o-x-mark')
|
||||
->trueColor('success')
|
||||
->falseColor('danger'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use App\Models\Item;
|
||||
use App\Models\Category;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Type extends Model
|
||||
class Category extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name'
|
||||
'name',
|
||||
'type'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Models;
|
||||
use App\Models\User;
|
||||
use App\Models\Type;
|
||||
use App\Models\Category;
|
||||
use App\Models\Reserveditem;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
|
@ -19,16 +19,20 @@ class Item extends Model
|
|||
'quantity',
|
||||
'cost',
|
||||
'can_be_loaned',
|
||||
'type_id'
|
||||
'category_id',
|
||||
'players',
|
||||
'play_time',
|
||||
'age',
|
||||
'type'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* Get the type of the item
|
||||
*/
|
||||
public function type(): BelongsTo
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Type::class);
|
||||
return $this->belongsTo(Category::class);
|
||||
}
|
||||
|
||||
public function reserveditem()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ class Reserveditem extends Model
|
|||
'delivered',
|
||||
'returned',
|
||||
'user_id',
|
||||
'item_id'
|
||||
'item_id',
|
||||
'email'
|
||||
];
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ return new class extends Migration
|
|||
$table->string('desc')->nullable();
|
||||
$table->date('acquisition_date')->nullable();
|
||||
$table->string('image')->nullable();
|
||||
$table->integer('type_id')->nullable();
|
||||
$table->integer('category_id')->nullable();
|
||||
$table->integer('quantity')->nullable();
|
||||
$table->string('cost')->nullable();
|
||||
$table->boolean('can_be_loaned')->default(false);
|
||||
|
|
|
|||
|
|
@ -11,9 +11,10 @@ return new class extends Migration
|
|||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('types', function (Blueprint $table) {
|
||||
Schema::create('categories', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name')->required();
|
||||
$table->string('type')->required();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
|
@ -23,6 +24,6 @@ return new class extends Migration
|
|||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('types');
|
||||
Schema::dropIfExists('categories');
|
||||
}
|
||||
};
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
34
database/migrations/2025_02_24_120234_add_to_items_table.php
Normal file
34
database/migrations/2025_02_24_120234_add_to_items_table.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->string('players')->nullable();
|
||||
$table->string('age')->nullable();
|
||||
$table->string('play_time')->nullable();
|
||||
$table->string('type')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('players');
|
||||
$table->dropColumn('age');
|
||||
$table->dropColumn('play_time');
|
||||
$table->dropColumn('type');
|
||||
});
|
||||
}
|
||||
};
|
||||
BIN
public/img/logo.png
Normal file
BIN
public/img/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
|
|
@ -1,3 +1,8 @@
|
|||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
|
||||
#reserve-form-container {
|
||||
max-width: 1400px !important;
|
||||
}
|
||||
15
resources/views/filament/pages/reserve.blade.php
Normal file
15
resources/views/filament/pages/reserve.blade.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
|
||||
<div id="reserve-form-container">
|
||||
<nav class="py-2 flex h-16 items-center align-items gap-x-4 bg-white px-4 shadow-sm ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10 md:px-6 lg:px-8">
|
||||
<img class=" w-auto h-full" src="/img/logo.png" alt="logo">
|
||||
<h1 class="fi-logo flex text-xl font-bold leading-5 tracking-tight text-gray-950 dark:text-white">vBytes</h1>
|
||||
</nav>
|
||||
<div class="py-12 mx-auto h-full w-full px-4 md:px-6 lg:px-8 max-w-7xl">
|
||||
<h1 class="fi-header-heading text-2xl font-bold tracking-tight text-gray-950 dark:text-white sm:text-3xl">Game booking</h1>
|
||||
<p class="py-4">Welcome! Here you can make a reservation for a game.</p>
|
||||
</div>
|
||||
<div class="mx-auto h-full w-full px-4 md:px-6 lg:px-8 max-w-7xl">
|
||||
{{ $this->table }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -4,6 +4,7 @@ use App\Http\Controllers\ProfileController;
|
|||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Inertia\Inertia;
|
||||
use App\Filament\Pages\Reserve;
|
||||
|
||||
//Route::get('/', function () {
|
||||
// return Inertia::render('Welcome', [
|
||||
|
|
@ -24,4 +25,6 @@ use Inertia\Inertia;
|
|||
// Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
|
||||
//});
|
||||
|
||||
Route::get('reserve', Reserve::class);
|
||||
|
||||
require __DIR__.'/auth.php';
|
||||
|
|
|
|||
Loading…
Reference in a new issue