Initial commit
This commit is contained in:
47
app/Filament/Resources/Links/LinkResource.php
Normal file
47
app/Filament/Resources/Links/LinkResource.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Links;
|
||||
|
||||
use App\Filament\Resources\Links\Pages\CreateLink;
|
||||
use App\Filament\Resources\Links\Pages\EditLink;
|
||||
use App\Filament\Resources\Links\Pages\ListLinks;
|
||||
use App\Filament\Resources\Links\Pages\ViewLink;
|
||||
use App\Filament\Resources\Links\Schemas\LinkForm;
|
||||
use App\Filament\Resources\Links\Schemas\LinkInfolist;
|
||||
use App\Filament\Resources\Links\Tables\LinksTable;
|
||||
use App\Models\Link;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class LinkResource extends Resource
|
||||
{
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('admin') ?? false;
|
||||
}
|
||||
|
||||
protected static ?string $model = Link::class;
|
||||
|
||||
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-link';
|
||||
protected static string | \UnitEnum | null $navigationGroup = 'Treść';
|
||||
protected static ?string $pluralModelLabel = 'Przyciski';
|
||||
protected static ?string $modelLabel = 'Przyciski';
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'Link';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return LinkForm::configure($schema);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => EditLink::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
26
app/Filament/Resources/Links/Pages/EditLink.php
Normal file
26
app/Filament/Resources/Links/Pages/EditLink.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Links\Pages;
|
||||
|
||||
use App\Filament\Resources\Links\LinkResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditLink extends EditRecord
|
||||
{
|
||||
protected static string $resource = LinkResource::class;
|
||||
|
||||
public function mount($record = null): void
|
||||
{
|
||||
$record = $record ?? 1;
|
||||
parent::mount($record);
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
66
app/Filament/Resources/Links/Schemas/LinkForm.php
Normal file
66
app/Filament/Resources/Links/Schemas/LinkForm.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Links\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Builder;
|
||||
use Filament\Forms\Components\Builder\Block;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class LinkForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Section::make()
|
||||
->schema([
|
||||
Builder::make('links')
|
||||
->label('Przyciski')
|
||||
->addActionLabel('Dodaj przycisk')
|
||||
->collapsible()
|
||||
->collapsed()
|
||||
->reorderable()
|
||||
->blocks([
|
||||
Block::make('link')
|
||||
->label(function (?array $state): string {
|
||||
if ($state === null) {
|
||||
return 'Odnośnik';
|
||||
}
|
||||
|
||||
return $state['name'] ?? 'Odnośnik';
|
||||
})
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Nazwa')
|
||||
->required(),
|
||||
TextInput::make('icon')
|
||||
->label('Ikona (FontAwesome)')
|
||||
->required(),
|
||||
Select::make('btn_style')
|
||||
->label('Styl przycisku')
|
||||
->options([
|
||||
'primary' => 'Pomarańczowy',
|
||||
'secondary' => 'Szary',
|
||||
])
|
||||
->default('primary')
|
||||
->required(),
|
||||
TextInput::make('link')
|
||||
->label('Link')
|
||||
->required(),
|
||||
Toggle::make('external')
|
||||
->label('Zewnętrzny link')
|
||||
->required(),
|
||||
Toggle::make('new_tab')
|
||||
->label('Otwieraj w nowym oknie')
|
||||
->required(),
|
||||
])
|
||||
->columns(2),
|
||||
])
|
||||
])
|
||||
])->statePath('data');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user