mirror of
https://github.com/nihonbuzz/nihonbuzz-academy.git
synced 2026-01-27 05:51:57 +07:00
first commit
This commit is contained in:
123
app/Filament/Resources/Lessons/LessonResource.php
Normal file
123
app/Filament/Resources/Lessons/LessonResource.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Lessons;
|
||||
|
||||
use App\Filament\Resources\Lessons\Pages\CreateLesson;
|
||||
use App\Filament\Resources\Lessons\Pages\EditLesson;
|
||||
use App\Filament\Resources\Lessons\Pages\ListLessons;
|
||||
use App\Filament\Resources\Lessons\Schemas\LessonForm;
|
||||
use App\Filament\Resources\Lessons\Tables\LessonsTable;
|
||||
use App\Models\Lesson;
|
||||
use BackedEnum;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class LessonResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Lesson::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-play-circle';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'title';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->schema([
|
||||
Forms\Components\Select::make('module_id')
|
||||
->relationship('module', 'title')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(fn ($state, $set) => $set('slug', \Illuminate\Support\Str::slug($state))),
|
||||
Forms\Components\TextInput::make('slug')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->unique(ignoreRecord: true),
|
||||
Forms\Components\Select::make('type')
|
||||
->options([
|
||||
'video' => 'Video',
|
||||
'text' => 'Text',
|
||||
'quiz' => 'Quiz',
|
||||
'vocab_list' => 'Vocabulary List',
|
||||
])
|
||||
->default('text')
|
||||
->required(),
|
||||
Forms\Components\FileUpload::make('content_pdf')
|
||||
->label('Lesson PDF (Paid Content)')
|
||||
->disk('r2_private')
|
||||
->directory('pdfs')
|
||||
->visibility('private')
|
||||
->acceptedFileTypes(['application/pdf'])
|
||||
->downloadable()
|
||||
->columnSpanFull(),
|
||||
Forms\Components\RichEditor::make('content')
|
||||
->columnSpanFull(),
|
||||
Forms\Components\TextInput::make('video_url')
|
||||
->label('Video URL (YouTube/Vimeo)')
|
||||
->url(),
|
||||
Forms\Components\Toggle::make('is_free_preview')
|
||||
->label('Free Preview?')
|
||||
->default(false),
|
||||
Forms\Components\TextInput::make('order_index')
|
||||
->numeric()
|
||||
->default(0),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('module.title')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->badge(),
|
||||
Tables\Columns\IconColumn::make('is_free_preview')
|
||||
->boolean(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->defaultSort('order_index', 'asc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListLessons::route('/'),
|
||||
'create' => CreateLesson::route('/create'),
|
||||
'edit' => EditLesson::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getRecordRouteBindingEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getRecordRouteBindingEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/Lessons/Pages/CreateLesson.php
Normal file
11
app/Filament/Resources/Lessons/Pages/CreateLesson.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Lessons\Pages;
|
||||
|
||||
use App\Filament\Resources\Lessons\LessonResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateLesson extends CreateRecord
|
||||
{
|
||||
protected static string $resource = LessonResource::class;
|
||||
}
|
||||
23
app/Filament/Resources/Lessons/Pages/EditLesson.php
Normal file
23
app/Filament/Resources/Lessons/Pages/EditLesson.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Lessons\Pages;
|
||||
|
||||
use App\Filament\Resources\Lessons\LessonResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditLesson extends EditRecord
|
||||
{
|
||||
protected static string $resource = LessonResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
ForceDeleteAction::make(),
|
||||
RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Filament/Resources/Lessons/Pages/ListLessons.php
Normal file
19
app/Filament/Resources/Lessons/Pages/ListLessons.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Lessons\Pages;
|
||||
|
||||
use App\Filament\Resources\Lessons\LessonResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListLessons extends ListRecords
|
||||
{
|
||||
protected static string $resource = LessonResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
45
app/Filament/Resources/Lessons/Schemas/LessonForm.php
Normal file
45
app/Filament/Resources/Lessons/Schemas/LessonForm.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Lessons\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class LessonForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('module_id')
|
||||
->relationship('module', 'title')
|
||||
->required(),
|
||||
TextInput::make('title')
|
||||
->required(),
|
||||
TextInput::make('slug')
|
||||
->required(),
|
||||
TextInput::make('type')
|
||||
->required()
|
||||
->default('text'),
|
||||
Textarea::make('content')
|
||||
->columnSpanFull(),
|
||||
TextInput::make('video_url')
|
||||
->url(),
|
||||
TextInput::make('duration_seconds')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(0),
|
||||
Toggle::make('is_free_preview')
|
||||
->required(),
|
||||
TextInput::make('order_index')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(0),
|
||||
Textarea::make('metadata')
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
69
app/Filament/Resources/Lessons/Tables/LessonsTable.php
Normal file
69
app/Filament/Resources/Lessons/Tables/LessonsTable.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Lessons\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ForceDeleteBulkAction;
|
||||
use Filament\Actions\RestoreBulkAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\TrashedFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class LessonsTable
|
||||
{
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
TextColumn::make('module.title')
|
||||
->searchable(),
|
||||
TextColumn::make('title')
|
||||
->searchable(),
|
||||
TextColumn::make('slug')
|
||||
->searchable(),
|
||||
TextColumn::make('type')
|
||||
->searchable(),
|
||||
TextColumn::make('video_url')
|
||||
->searchable(),
|
||||
TextColumn::make('duration_seconds')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
IconColumn::make('is_free_preview')
|
||||
->boolean(),
|
||||
TextColumn::make('order_index')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('deleted_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
TrashedFilter::make(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
ForceDeleteBulkAction::make(),
|
||||
RestoreBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user