college-courses/app/Http/Livewire/Course/CourseManage.php

62 lines
1.5 KiB
PHP
Raw Normal View History

2024-10-15 10:15:40 +03:00
<?php
namespace App\Http\Livewire\Course;
use App\Models\Course;
use Closure;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
class CourseManage extends Component implements HasTable
{
use InteractsWithTable;
public function mount()
{
}
public function createCourse()
{
return redirect()->route('course-create');
}
protected function getTableQuery()
{
if (Auth::user()->isRole('admin')) {
return Course::query();
}
return Course::query()->where('user_id', Auth::id());
}
protected function getTableColumns(): array
{
return [
TextColumn::make('name')->label('Название'),
];
}
protected function getTableActions(): array
{
return [
Action::make('edit')->label('Редактировать')
->url(fn (Course $record): string => route('course-edit', [
'course' => $record
])),
Action::make('delete')->label('Удалить')->color('danger')
->action(function (Course $record) {
return $record->delete();
}),
];
}
public function render()
{
return view('livewire.course.course-manage')->layout('layouts.simple-page');
}
}