feat: Automatically assign author ID in news creation form and update news table views column.
This commit is contained in:
parent
acd5e1afef
commit
e35a4c5985
@ -7,7 +7,6 @@
|
|||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class CreateNews extends CreateRecord
|
class CreateNews extends CreateRecord
|
||||||
{
|
{
|
||||||
@ -35,11 +34,4 @@ protected function getRedirectUrl(): string
|
|||||||
{
|
{
|
||||||
return $this->getResource()::getUrl('index');
|
return $this->getResource()::getUrl('index');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function handleRecordCreation(array $data): Model
|
|
||||||
{
|
|
||||||
$data['author_id'] = auth()->id();
|
|
||||||
|
|
||||||
return static::getModel()::create($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,9 @@ public static function configure(Schema $schema): Schema
|
|||||||
{
|
{
|
||||||
return $schema
|
return $schema
|
||||||
->components([
|
->components([
|
||||||
|
Hidden::make('author_id')
|
||||||
|
->default(auth()->id()),
|
||||||
|
|
||||||
Section::make([
|
Section::make([
|
||||||
TextInput::make('title')
|
TextInput::make('title')
|
||||||
->label('Judul')
|
->label('Judul')
|
||||||
|
|||||||
@ -33,13 +33,6 @@ public static function configure(Table $table): Table
|
|||||||
->searchable()
|
->searchable()
|
||||||
->sortable()
|
->sortable()
|
||||||
->placeholder('Tidak ada'),
|
->placeholder('Tidak ada'),
|
||||||
|
|
||||||
TextColumn::make('view')
|
|
||||||
->label('Dilihat')
|
|
||||||
->numeric()
|
|
||||||
->sortable()
|
|
||||||
->alignCenter(),
|
|
||||||
|
|
||||||
TextColumn::make('categories.name')
|
TextColumn::make('categories.name')
|
||||||
->label('Kategori')
|
->label('Kategori')
|
||||||
->listWithLineBreaks()
|
->listWithLineBreaks()
|
||||||
@ -73,6 +66,11 @@ public static function configure(Table $table): Table
|
|||||||
->formatStateUsing(fn (NewsStatus $state): string => $state->getLabel())
|
->formatStateUsing(fn (NewsStatus $state): string => $state->getLabel())
|
||||||
->color(fn (NewsStatus $state): string => $state->getColor()),
|
->color(fn (NewsStatus $state): string => $state->getColor()),
|
||||||
|
|
||||||
|
TextColumn::make('views')
|
||||||
|
->label('Dilihat')
|
||||||
|
->sortable()
|
||||||
|
->alignCenter(),
|
||||||
|
|
||||||
TextColumn::make('published_at')
|
TextColumn::make('published_at')
|
||||||
->label('Tgl Publish')
|
->label('Tgl Publish')
|
||||||
->searchable()
|
->searchable()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user