fix: gabungkan MyPostResource ke PostResource dengan scope dan UI adaptif per role

This commit is contained in:
2026-04-03 07:01:46 +07:00
parent a7e10600d4
commit 764aa4d82f
10 changed files with 62 additions and 202 deletions
+21 -1
View File
@@ -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
{