55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Livewire\Lesson;
|
|
|
|
use App\Models\Course;
|
|
use App\Models\Lesson;
|
|
use Closure;
|
|
use Filament\Forms\Components\MarkdownEditor;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Concerns\InteractsWithForms;
|
|
use Filament\Forms\Contracts\HasForms;
|
|
use Livewire\Component;
|
|
use Illuminate\Support\Str;
|
|
|
|
class LessonCreate extends Component implements HasForms
|
|
{
|
|
use InteractsWithForms;
|
|
|
|
public $name;
|
|
public $slug;
|
|
public $body;
|
|
public Course $course;
|
|
|
|
public function mount()
|
|
{
|
|
}
|
|
|
|
protected function getFormSchema(): array
|
|
{
|
|
return [
|
|
TextInput::make('name')
|
|
->label('Название занятия')
|
|
->required()
|
|
->reactive()
|
|
->afterStateUpdated(function (Closure $set, $state) {
|
|
$set('slug', Str::slug($state));
|
|
}),
|
|
TextInput::make('slug')
|
|
->required()
|
|
->label('Название в url-ссылке'),
|
|
MarkdownEditor::make('body')
|
|
];
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
Lesson::create(array_merge($this->form->getState(), ['course_id' => $this->course->id]));
|
|
return redirect()->route('course-edit', ['course' => $this->course]);
|
|
}
|
|
public function render()
|
|
{
|
|
return view('livewire.lesson.lesson-create')->layout('layouts.base');
|
|
}
|
|
}
|