-
-
Save oliuz/83fc2ec0b78ec9a59ea0a06d4ab66159 to your computer and use it in GitHub Desktop.
Filament Resrouces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Filament\Resources; | |
use App\Filament\Resources\CategoryResource\Pages; | |
use App\Filament\Resources\CategoryResource\RelationManagers; | |
use App\Filament\Resources\CategoryResource\RelationManagers\PostsRelationManager; | |
use App\Models\Category; | |
use Filament\Forms; | |
use Filament\Forms\Components\TextInput; | |
use Filament\Forms\Form; | |
use Filament\Resources\Resource; | |
use Filament\Tables; | |
use Filament\Tables\Columns\TextColumn; | |
use Filament\Tables\Table; | |
use Illuminate\Database\Eloquent\Builder; | |
use Illuminate\Database\Eloquent\SoftDeletingScope; | |
class CategoryResource extends Resource | |
{ | |
protected static ?string $model = Category::class; | |
protected static ?string $navigationIcon = 'heroicon-o-tag'; | |
protected static ?string $modelLabel = 'Post Categories'; | |
public static function form(Form $form): Form | |
{ | |
return $form | |
->schema([ | |
TextInput::make('name')->required(), | |
TextInput::make('slug')->required(), | |
]); | |
} | |
public static function table(Table $table): Table | |
{ | |
return $table | |
->columns([ | |
TextColumn::make('name'), | |
TextColumn::make('slug'), | |
]) | |
->filters([ | |
// | |
]) | |
->actions([ | |
Tables\Actions\EditAction::make(), | |
]) | |
->bulkActions([ | |
Tables\Actions\BulkActionGroup::make([ | |
Tables\Actions\DeleteBulkAction::make(), | |
]), | |
]) | |
->emptyStateActions([ | |
Tables\Actions\CreateAction::make(), | |
]); | |
} | |
public static function getRelations(): array | |
{ | |
return [ | |
PostsRelationManager::class | |
]; | |
} | |
public static function getPages(): array | |
{ | |
return [ | |
'index' => Pages\ListCategories::route('/'), | |
'create' => Pages\CreateCategory::route('/create'), | |
'edit' => Pages\EditCategory::route('/{record}/edit'), | |
]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Filament\Resources; | |
use App\Filament\Resources\PostResource\Pages; | |
use App\Filament\Resources\PostResource\RelationManagers; | |
use App\Filament\Resources\PostResource\RelationManagers\AuthorsRelationManager; | |
use App\Models\Category; | |
use App\Models\Post; | |
use App\Models\User; | |
use Filament\Forms; | |
use Filament\Forms\Components\Actions\Action; | |
use Filament\Forms\Components\Checkbox; | |
use Filament\Forms\Components\CheckboxList; | |
use Filament\Forms\Components\ColorPicker; | |
use Filament\Forms\Components\FileUpload; | |
use Filament\Forms\Components\Group; | |
use Filament\Forms\Components\MarkdownEditor; | |
use Filament\Forms\Components\Section; | |
use Filament\Forms\Components\Select; | |
use Filament\Forms\Components\TagsInput; | |
use Filament\Forms\Components\TextInput; | |
use Filament\Forms\Form; | |
use Filament\Forms\Set; | |
use Filament\Resources\Resource; | |
use Filament\Tables; | |
use Filament\Tables\Columns\CheckboxColumn; | |
use Filament\Tables\Columns\ColorColumn; | |
use Filament\Tables\Columns\ImageColumn; | |
use Filament\Tables\Columns\TextColumn; | |
use Filament\Tables\Table; | |
class PostResource extends Resource | |
{ | |
protected static ?string $model = Post::class; | |
protected static ?string $navigationIcon = 'heroicon-o-folder'; | |
public static function form(Form $form): Form | |
{ | |
return $form | |
->schema([ | |
Section::make('Create a Post') | |
->description('create posts over here.') | |
->schema([ | |
TextInput::make('title')->rules('min:3|max:10')->required() , | |
TextInput::make('slug')->unique(ignoreRecord: true)->required(), | |
Select::make('category_id') | |
->label('Category') | |
->relationship('category', 'name') | |
->searchable() | |
->required(), | |
ColorPicker::make('color')->required(), | |
MarkdownEditor::make('content')->required()->columnSpanFull(), | |
])->columnSpan(2)->columns(2), | |
Group::make()->schema([ | |
Section::make("Image") | |
->collapsible() | |
->schema([ | |
FileUpload::make('thumbnail')->disk('public')->directory('thumbnails'), | |
])->columnSpan(1), | |
Section::make('Meta')->schema([ | |
TagsInput::make('tags')->required(), | |
Checkbox::make('published'), | |
]), | |
// Section::make('Authors')->schema([ | |
// CheckboxList::make('authors') | |
// ->label('Co Authors') | |
// // ->multiple() | |
// ->relationship('authors', 'name') | |
// ]) | |
]), | |
])->columns([ | |
'default' => 3, | |
'sm' => 3, | |
'md' => 3, | |
'lg' => 3 | |
]); | |
} | |
public static function table(Table $table): Table | |
{ | |
return $table | |
->columns([ | |
TextColumn::make('id') | |
->sortable() | |
->searchable() | |
->toggleable(isToggledHiddenByDefault: true), | |
ImageColumn::make('thumbnail') | |
->toggleable(), | |
ColorColumn::make('color') | |
->toggleable(), | |
TextColumn::make('title') | |
->sortable() | |
->searchable() | |
->toggleable(), | |
TextColumn::make('slug') | |
->sortable() | |
->searchable() | |
->toggleable(), | |
TextColumn::make('category.name') | |
->sortable() | |
->searchable() | |
->toggleable(), | |
TextColumn::make('tags') | |
->toggleable(), | |
CheckboxColumn::make('published') | |
->toggleable(), | |
TextColumn::make('created_at') | |
->label('Published on') | |
->date() | |
->sortable() | |
->searchable() | |
->toggleable(), | |
]) | |
->filters([ | |
// | |
]) | |
->actions([ | |
Tables\Actions\EditAction::make(), | |
Tables\Actions\DeleteAction::make() | |
]) | |
->bulkActions([ | |
Tables\Actions\BulkActionGroup::make([ | |
Tables\Actions\DeleteBulkAction::make(), | |
]), | |
]) | |
->emptyStateActions([ | |
Tables\Actions\CreateAction::make(), | |
]); | |
} | |
public static function getRelations(): array | |
{ | |
return [ | |
AuthorsRelationManager::class | |
]; | |
} | |
public static function getPages(): array | |
{ | |
return [ | |
'index' => Pages\ListPosts::route('/'), | |
'create' => Pages\CreatePost::route('/create'), | |
'edit' => Pages\EditPost::route('/{record}/edit'), | |
]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Filament\Resources\CategoryResource\RelationManagers; | |
use Filament\Forms; | |
use Filament\Forms\Form; | |
use Filament\Resources\RelationManagers\RelationManager; | |
use Filament\Tables; | |
use Filament\Tables\Table; | |
use Illuminate\Database\Eloquent\Builder; | |
use Illuminate\Database\Eloquent\SoftDeletingScope; | |
use Filament\Forms\Components\Checkbox; | |
use Filament\Forms\Components\ColorPicker; | |
use Filament\Forms\Components\FileUpload; | |
use Filament\Forms\Components\Group; | |
use Filament\Forms\Components\MarkdownEditor; | |
use Filament\Forms\Components\Section; | |
use Filament\Forms\Components\Select; | |
use Filament\Forms\Components\TagsInput; | |
use Filament\Forms\Components\TextInput; | |
class PostsRelationManager extends RelationManager | |
{ | |
protected static string $relationship = 'posts'; | |
public function form(Form $form): Form | |
{ | |
return $form | |
->schema([ | |
Section::make('Create a Post') | |
->description('create posts over here.') | |
->schema([ | |
TextInput::make('title')->rules('min:3|max:10')->required(), | |
TextInput::make('slug')->unique(ignoreRecord: true)->required(), | |
ColorPicker::make('color')->required(), | |
MarkdownEditor::make('content')->required()->columnSpanFull(), | |
])->columnSpan(2)->columns(2), | |
Group::make()->schema([ | |
Section::make("Image") | |
->collapsible() | |
->schema([ | |
FileUpload::make('thumbnail')->disk('public')->directory('thumbnails'), | |
])->columnSpan(1), | |
Section::make('Meta')->schema([ | |
TagsInput::make('tags')->required(), | |
Checkbox::make('published'), | |
]) | |
]), | |
])->columns([ | |
'default' => 3, | |
'sm' => 3, | |
'md' => 3, | |
'lg' => 3 | |
]); | |
} | |
public function table(Table $table): Table | |
{ | |
return $table | |
->recordTitleAttribute('title') | |
->columns([ | |
Tables\Columns\TextColumn::make('title'), | |
Tables\Columns\TextColumn::make('slug'), | |
Tables\Columns\CheckboxColumn::make('published'), | |
]) | |
->filters([ | |
// | |
]) | |
->headerActions([ | |
Tables\Actions\CreateAction::make(), | |
]) | |
->actions([ | |
Tables\Actions\EditAction::make(), | |
Tables\Actions\DeleteAction::make(), | |
]) | |
->bulkActions([ | |
Tables\Actions\BulkActionGroup::make([ | |
Tables\Actions\DeleteBulkAction::make(), | |
]), | |
]) | |
->emptyStateActions([ | |
Tables\Actions\CreateAction::make(), | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment