feat: Automatically assign author ID in news creation form and update news table views column.

This commit is contained in:
Yoga Pangestu 2026-01-27 21:45:59 +07:00
parent acd5e1afef
commit e35a4c5985
3 changed files with 8 additions and 15 deletions

View File

@ -7,7 +7,6 @@
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
class CreateNews extends CreateRecord
{
@ -35,11 +34,4 @@ protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('index');
}
protected function handleRecordCreation(array $data): Model
{
$data['author_id'] = auth()->id();
return static::getModel()::create($data);
}
}

View File

@ -22,6 +22,9 @@ public static function configure(Schema $schema): Schema
{
return $schema
->components([
Hidden::make('author_id')
->default(auth()->id()),
Section::make([
TextInput::make('title')
->label('Judul')

View File

@ -33,13 +33,6 @@ public static function configure(Table $table): Table
->searchable()
->sortable()
->placeholder('Tidak ada'),
TextColumn::make('view')
->label('Dilihat')
->numeric()
->sortable()
->alignCenter(),
TextColumn::make('categories.name')
->label('Kategori')
->listWithLineBreaks()
@ -73,6 +66,11 @@ public static function configure(Table $table): Table
->formatStateUsing(fn (NewsStatus $state): string => $state->getLabel())
->color(fn (NewsStatus $state): string => $state->getColor()),
TextColumn::make('views')
->label('Dilihat')
->sortable()
->alignCenter(),
TextColumn::make('published_at')
->label('Tgl Publish')
->searchable()