mirror of
https://github.com/anna-sara/filament_inventory
synced 2025-10-26 23:27:13 +01:00
Removed Type
This commit is contained in:
parent
daca1c7886
commit
0db7047403
7 changed files with 128 additions and 223 deletions
|
|
@ -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,106 @@ 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()
|
||||
],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([
|
||||
|
|
|
|||
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\TypeResource\Pages;
|
||||
use App\Filament\Resources\TypeResource\RelationManagers;
|
||||
use App\Models\Type;
|
||||
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;
|
||||
|
||||
class TypeResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Type::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-bookmark';
|
||||
|
||||
protected static ?string $modelLabel = 'Item types';
|
||||
|
||||
protected static ?string $title = 'Item Types';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Name')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListTypes::route('/'),
|
||||
'create' => Pages\CreateType::route('/create'),
|
||||
'edit' => Pages\EditType::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function canViewAny(): bool
|
||||
{
|
||||
return auth()->user()->is_admin==true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateType extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$data['user_id'] = auth()->id();
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditType extends EditRecord
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getRedirectUrl(): string
|
||||
{
|
||||
return $this->getResource()::getUrl('index');
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TypeResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTypes extends ListRecords
|
||||
{
|
||||
protected static string $resource = TypeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make()->label('Create new'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
use App\Models\Item;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Type extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the items for the type.
|
||||
*/
|
||||
public function item(): HasMany
|
||||
{
|
||||
return $this->hasMany(Item::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
<?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::create('types', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name')->required();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('types');
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue