fix: gabungkan MyPostResource ke PostResource dengan scope dan UI adaptif per role
This commit is contained in:
@@ -11,13 +11,33 @@ use App\Models\Post;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class PostResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Post::class;
|
||||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-newspaper';
|
||||
protected static string|\UnitEnum|null $navigationGroup = 'Konten';
|
||||
protected static ?string $modelLabel = 'Artikel';
|
||||
|
||||
// Label dinamis sesuai role
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return auth()->user()?->hasAnyRole(['super_admin', 'ketua', 'auditor'])
|
||||
? 'Artikel'
|
||||
: 'Artikel Saya';
|
||||
}
|
||||
|
||||
// Scope: ketua/super_admin/auditor lihat semua, lainnya hanya milik sendiri
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
$query = parent::getEloquentQuery();
|
||||
|
||||
if (auth()->user()?->hasAnyRole(['super_admin', 'ketua', 'auditor'])) {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->where('author_id', auth()->id());
|
||||
}
|
||||
|
||||
public static function form(Schema $form): Schema
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user