feat(level): Ajout de la table level
This commit is contained in:
parent
466b14dd6c
commit
45f5413c52
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Levels;
|
||||
|
||||
use App\Filament\Resources\Levels\Pages\CreateLevel;
|
||||
use App\Filament\Resources\Levels\Pages\EditLevel;
|
||||
use App\Filament\Resources\Levels\Pages\ListLevels;
|
||||
use App\Filament\Resources\Levels\Schemas\LevelForm;
|
||||
use App\Filament\Resources\Levels\Tables\LevelsTable;
|
||||
use App\Models\Level;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class LevelResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Level::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'label';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return LevelForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return LevelsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListLevels::route('/'),
|
||||
'create' => CreateLevel::route('/create'),
|
||||
'edit' => EditLevel::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Levels\Pages;
|
||||
|
||||
use App\Filament\Resources\Levels\LevelResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateLevel extends CreateRecord
|
||||
{
|
||||
protected static string $resource = LevelResource::class;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Levels\Pages;
|
||||
|
||||
use App\Filament\Resources\Levels\LevelResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditLevel extends EditRecord
|
||||
{
|
||||
protected static string $resource = LevelResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Levels\Pages;
|
||||
|
||||
use App\Filament\Resources\Levels\LevelResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListLevels extends ListRecords
|
||||
{
|
||||
protected static string $resource = LevelResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Levels\Schemas;
|
||||
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class LevelForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('level_position')
|
||||
->numeric(),
|
||||
TextInput::make('xpThreshold')
|
||||
->required()
|
||||
->numeric(),
|
||||
TextInput::make('label')
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Levels\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class LevelsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('level_position')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('xpThreshold')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('label')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
@ -48,11 +48,7 @@ class UserForm
|
|||
->image()
|
||||
->avatar()
|
||||
->disk('public')
|
||||
->directory('avatars'),
|
||||
TextInput::make('level')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(1),
|
||||
->directory('avatars')
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
class HuntSteps extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
protected $fillable = [
|
||||
'hunt_id',
|
||||
'step_number',
|
||||
'title',
|
||||
|
|
|
|||
|
|
@ -2,9 +2,21 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\User;
|
||||
|
||||
class Level extends Model
|
||||
{
|
||||
//
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'level_position',
|
||||
'xpThreshold',
|
||||
'label',
|
||||
];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ class User extends Authenticatable implements HasName, FilamentUser
|
|||
'level',
|
||||
'avatar_uri',
|
||||
'participations',
|
||||
'victories'
|
||||
'victories',
|
||||
'level_id'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ return new class extends Migration
|
|||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->foreignId('level_id');
|
||||
$table->foreignId('level_id')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue