Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions admin/app/Filament/Resources/SettingResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Resources\SettingResource\Pages\CreateSetting;
use App\Filament\Resources\SettingResource\Pages\EditSetting;
use App\Filament\Resources\SettingResource\Pages\ListSettings;
use App\Models\Setting;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class SettingResource extends Resource
{
protected static ?string $model = Setting::class;

protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-cog-6-tooth';

public static function getNavigationGroup(): ?string
{
return trans('setting.navigation_group');
}

public static function getModelLabel(): string
{
return trans('setting.label');
}

public static function getPluralModelLabel(): string
{
return trans('setting.plural_label');
}

public static function form(Schema $schema): Schema
{
return $schema
->components([
TextInput::make('key')
->label(trans('setting.key'))
->required()
->maxLength(255)
->unique(Setting::class, 'key', ignoreRecord: true),
TextInput::make('label')
->label(trans('setting.label_field'))
->maxLength(255),
Toggle::make('autoload')
->label(trans('setting.autoload'))
->default(true),
Textarea::make('content')
->label(trans('setting.content'))
->columnSpanFull(),
]);
}

public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->columns([
TextColumn::make('id')
->label('#')
->sortable(),
TextColumn::make('key')
->label(trans('setting.key'))
->searchable(),
TextColumn::make('label')
->label(trans('setting.label_field'))
->searchable()
->limit(30)
->wrap(),
IconColumn::make('autoload')
->label(trans('setting.autoload'))
->boolean()
->sortable(),
TextColumn::make('created_at')
->label(trans('setting.created_at'))
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
])
->recordActions([
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => ListSettings::route('/'),
'create' => CreateSetting::route('/create'),
'edit' => EditSetting::route('/{record}/edit'),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\SettingResource\Pages;

use App\Filament\Resources\SettingResource;
use Filament\Resources\Pages\CreateRecord;

class CreateSetting extends CreateRecord
{
protected static string $resource = SettingResource::class;

protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
}
26 changes: 26 additions & 0 deletions admin/app/Filament/Resources/SettingResource/Pages/EditSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\SettingResource\Pages;

use App\Filament\Resources\SettingResource;
use Filament\Actions\DeleteAction;
use Filament\Resources\Pages\EditRecord;

class EditSetting extends EditRecord
{
protected static string $resource = SettingResource::class;

protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}

protected function getHeaderActions(): array
{
return [
DeleteAction::make(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\SettingResource\Pages;

use App\Filament\Resources\SettingResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;

class ListSettings extends ListRecords
{
protected static string $resource = SettingResource::class;

protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}
36 changes: 36 additions & 0 deletions admin/app/Models/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Carbon\Carbon;
use Database\Factories\SettingFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
* @property positive-int $id
* @property string $key
* @property string|null $label
* @property string|null $content
* @property bool $autoload
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*/
class Setting extends Model
{
/** @use HasFactory<SettingFactory> */
use HasFactory;

protected $fillable = [
'key',
'label',
'content',
'autoload',
];

protected $casts = [
'autoload' => 'boolean',
];
}
27 changes: 27 additions & 0 deletions admin/database/factories/SettingFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\Setting;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends Factory<Setting>
*/
class SettingFactory extends Factory
{
/**
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'key' => fake()->unique()->slug(2),
'label' => fake()->optional()->words(2, true),
'content' => fake()->optional()->sentence(),
'autoload' => fake()->boolean(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('settings', function (Blueprint $table): void {
$table->id();
$table->string('key')->unique();
$table->string('label')->nullable();
$table->text('content')->nullable();
$table->boolean('autoload')->default(true);
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists('settings');
}
};
1 change: 1 addition & 0 deletions admin/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function run(): void
AncestorSeeder::class,
AttributeSeeder::class,
AttributeGroupCategorySeeder::class,
SettingSeeder::class,
]);
}
}
Loading
Loading