Refactor GroupResource to use a static property for navigation icon; add method documentation for name attribute in Group model.
This commit is contained in:
11
app/Filament/Resources/Rooms/Pages/CreateRoom.php
Normal file
11
app/Filament/Resources/Rooms/Pages/CreateRoom.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Rooms\Pages;
|
||||
|
||||
use App\Filament\Resources\Rooms\RoomResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateRoom extends CreateRecord
|
||||
{
|
||||
protected static string $resource = RoomResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Rooms/Pages/EditRoom.php
Normal file
19
app/Filament/Resources/Rooms/Pages/EditRoom.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Rooms\Pages;
|
||||
|
||||
use App\Filament\Resources\Rooms\RoomResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditRoom extends EditRecord
|
||||
{
|
||||
protected static string $resource = RoomResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Rooms/Pages/ListRooms.php
Normal file
19
app/Filament/Resources/Rooms/Pages/ListRooms.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Rooms\Pages;
|
||||
|
||||
use App\Filament\Resources\Rooms\RoomResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListRooms extends ListRecords
|
||||
{
|
||||
protected static string $resource = RoomResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
57
app/Filament/Resources/Rooms/RoomResource.php
Normal file
57
app/Filament/Resources/Rooms/RoomResource.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Rooms;
|
||||
|
||||
use App\Filament\Resources\Rooms\Pages\CreateRoom;
|
||||
use App\Filament\Resources\Rooms\Pages\EditRoom;
|
||||
use App\Filament\Resources\Rooms\Pages\ListRooms;
|
||||
use App\Filament\Resources\Rooms\Schemas\RoomForm;
|
||||
use App\Filament\Resources\Rooms\Tables\RoomsTable;
|
||||
use App\Models\Room;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class RoomResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Room::class;
|
||||
|
||||
protected static ?string $navigationLabel = 'Otaglar';
|
||||
|
||||
protected static ?string $pluralLabel = 'Otaglar';
|
||||
protected static ?string $modelLabel = 'Otag';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
protected static string | BackedEnum | null $navigationIcon = 'icon-door-open';
|
||||
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return RoomForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table->columns(RoomsTable::schema());
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListRooms::route('/'),
|
||||
'create' => CreateRoom::route('/create'),
|
||||
'edit' => EditRoom::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Filament/Resources/Rooms/Schemas/RoomForm.php
Normal file
36
app/Filament/Resources/Rooms/Schemas/RoomForm.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Rooms\Schemas;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class RoomForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Forms\Components\Select::make('hotel_id')
|
||||
->relationship('hotel', 'name')
|
||||
->required(),
|
||||
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required(),
|
||||
|
||||
Forms\Components\TextInput::make('floor')
|
||||
->required(),
|
||||
|
||||
Forms\Components\FileUpload::make('images')
|
||||
->multiple(),
|
||||
|
||||
Forms\Components\TextInput::make('bed_count')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(1),
|
||||
|
||||
Forms\Components\Checkbox::make('wide')
|
||||
->default(false)
|
||||
->required(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
33
app/Filament/Resources/Rooms/Tables/RoomsTable.php
Normal file
33
app/Filament/Resources/Rooms/Tables/RoomsTable.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Rooms\Tables;
|
||||
|
||||
use Filament\Tables;
|
||||
|
||||
class RoomsTable
|
||||
{
|
||||
public static function schema(): array
|
||||
{
|
||||
return [
|
||||
Tables\Columns\TextColumn::make('hotel.name')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('floor')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('bed_count')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
Tables\Columns\IconColumn::make('wide')
|
||||
->boolean(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user