Refactor GroupResource to use a static property for navigation icon; add method documentation for name attribute in Group model.
This commit is contained in:
58
app/Filament/Resources/Hotels/HotelResource.php
Normal file
58
app/Filament/Resources/Hotels/HotelResource.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Hotels;
|
||||
|
||||
use App\Filament\Resources\Hotels\Pages\CreateHotel;
|
||||
use App\Filament\Resources\Hotels\Pages\EditHotel;
|
||||
use App\Filament\Resources\Hotels\Pages\ListHotels;
|
||||
use App\Filament\Resources\Hotels\RelationManagers\RoomsRelationManager;
|
||||
use App\Filament\Resources\Hotels\Schemas\HotelForm;
|
||||
use App\Filament\Resources\Hotels\Tables\HotelsTable;
|
||||
use App\Models\Hotel;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class HotelResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Hotel::class;
|
||||
|
||||
protected static ?string $navigationLabel = 'Otellar';
|
||||
|
||||
protected static ?string $pluralLabel = 'Otellar';
|
||||
protected static ?string $modelLabel = 'Otel';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static string | BackedEnum | null $navigationIcon = 'heroicon-o-building-office';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->schema(HotelForm::schema());
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table->columns(HotelsTable::schema());
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RoomsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListHotels::route('/'),
|
||||
'create' => CreateHotel::route('/create'),
|
||||
'edit' => EditHotel::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Hotels/Pages/CreateHotel.php
Normal file
11
app/Filament/Resources/Hotels/Pages/CreateHotel.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Hotels\Pages;
|
||||
|
||||
use App\Filament\Resources\Hotels\HotelResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateHotel extends CreateRecord
|
||||
{
|
||||
protected static string $resource = HotelResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Hotels/Pages/EditHotel.php
Normal file
19
app/Filament/Resources/Hotels/Pages/EditHotel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Hotels\Pages;
|
||||
|
||||
use App\Filament\Resources\Hotels\HotelResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditHotel extends EditRecord
|
||||
{
|
||||
protected static string $resource = HotelResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Hotels/Pages/ListHotels.php
Normal file
19
app/Filament/Resources/Hotels/Pages/ListHotels.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Hotels\Pages;
|
||||
|
||||
use App\Filament\Resources\Hotels\HotelResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListHotels extends ListRecords
|
||||
{
|
||||
protected static string $resource = HotelResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Hotels\RelationManagers;
|
||||
|
||||
use Filament\Actions\AssociateAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\DissociateAction;
|
||||
use Filament\Actions\DissociateBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class RoomsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'rooms';
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make(),
|
||||
AssociateAction::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DissociateAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DissociateBulkAction::make(),
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
38
app/Filament/Resources/Hotels/Schemas/HotelForm.php
Normal file
38
app/Filament/Resources/Hotels/Schemas/HotelForm.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Hotels\Schemas;
|
||||
|
||||
use Filament\Forms;
|
||||
|
||||
class HotelForm
|
||||
{
|
||||
public static function schema(): array
|
||||
{
|
||||
return [
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required(),
|
||||
|
||||
Forms\Components\Select::make('city')
|
||||
->options([
|
||||
'Makkah' => 'Makkah',
|
||||
'Madinah' => 'Madinah',
|
||||
])
|
||||
->required(),
|
||||
|
||||
Forms\Components\FileUpload::make('image')
|
||||
->image(),
|
||||
Forms\Components\FileUpload::make('images')
|
||||
->multiple(),
|
||||
Forms\Components\TextInput::make('geo_location'),
|
||||
|
||||
Forms\Components\TextInput::make('haram_distance')
|
||||
->required(),
|
||||
|
||||
Forms\Components\TextInput::make('star')
|
||||
->required()
|
||||
->numeric()
|
||||
->minValue(1)
|
||||
->maxValue(5),
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Filament/Resources/Hotels/Tables/HotelsTable.php
Normal file
38
app/Filament/Resources/Hotels/Tables/HotelsTable.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Hotels\Tables;
|
||||
|
||||
use Filament\Tables;
|
||||
|
||||
class HotelsTable
|
||||
{
|
||||
public static function schema(): array
|
||||
{
|
||||
return [
|
||||
Tables\Columns\ImageColumn::make('image')
|
||||
->circular()
|
||||
->imageSize(60),
|
||||
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->searchable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('city')
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('haram_distance'),
|
||||
|
||||
Tables\Columns\TextColumn::make('star')
|
||||
->sortable(),
|
||||
|
||||
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