Initial commit
This commit is contained in:
50
app/Filament/Resources/Authors/AuthorResource.php
Normal file
50
app/Filament/Resources/Authors/AuthorResource.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Authors;
|
||||
|
||||
use App\Filament\Resources\Authors\Pages\CreateAuthor;
|
||||
use App\Filament\Resources\Authors\Pages\EditAuthor;
|
||||
use App\Filament\Resources\Authors\Pages\ListAuthors;
|
||||
use App\Filament\Resources\Authors\Schemas\AuthorForm;
|
||||
use App\Filament\Resources\Authors\Tables\AuthorsTable;
|
||||
use App\Models\Author;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AuthorResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Author::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::UserGroup;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return AuthorForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return AuthorsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListAuthors::route('/'),
|
||||
'create' => CreateAuthor::route('/create'),
|
||||
'edit' => EditAuthor::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Authors/Pages/CreateAuthor.php
Normal file
11
app/Filament/Resources/Authors/Pages/CreateAuthor.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Authors\Pages;
|
||||
|
||||
use App\Filament\Resources\Authors\AuthorResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAuthor extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AuthorResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/Authors/Pages/EditAuthor.php
Normal file
19
app/Filament/Resources/Authors/Pages/EditAuthor.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Authors\Pages;
|
||||
|
||||
use App\Filament\Resources\Authors\AuthorResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAuthor extends EditRecord
|
||||
{
|
||||
protected static string $resource = AuthorResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Authors/Pages/ListAuthors.php
Normal file
19
app/Filament/Resources/Authors/Pages/ListAuthors.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Authors\Pages;
|
||||
|
||||
use App\Filament\Resources\Authors\AuthorResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAuthors extends ListRecords
|
||||
{
|
||||
protected static string $resource = AuthorResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Filament/Resources/Authors/Schemas/AuthorForm.php
Normal file
30
app/Filament/Resources/Authors/Schemas/AuthorForm.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Authors\Schemas;
|
||||
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class AuthorForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->maxLength(255)
|
||||
->required(),
|
||||
TextInput::make('slug')
|
||||
->maxLength(255)
|
||||
->unique(ignoreRecord: true)
|
||||
->required(),
|
||||
TextInput::make('website')
|
||||
->url()
|
||||
->maxLength(500)
|
||||
->default(null),
|
||||
TextInput::make('user_id')
|
||||
->numeric()
|
||||
->default(null),
|
||||
]);
|
||||
}
|
||||
}
|
||||
47
app/Filament/Resources/Authors/Tables/AuthorsTable.php
Normal file
47
app/Filament/Resources/Authors/Tables/AuthorsTable.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Authors\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class AuthorsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->searchable(),
|
||||
TextColumn::make('slug')
|
||||
->searchable(),
|
||||
TextColumn::make('website')
|
||||
->searchable(),
|
||||
TextColumn::make('user_id')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user