From 6f409229f37666bfe12c1c84b5d633f86efbf252 Mon Sep 17 00:00:00 2001 From: THEVENOUX Jean-Philippe Date: Tue, 12 Mar 2024 14:12:37 +0100 Subject: [PATCH] feat: Edit Auth in Note (#8) Can modify User in add/edit note --- app/Livewire/Dashboard.php | 16 +++++++++++----- app/Models/Note.php | 5 +++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/Livewire/Dashboard.php b/app/Livewire/Dashboard.php index 3aeab5f..a603d52 100644 --- a/app/Livewire/Dashboard.php +++ b/app/Livewire/Dashboard.php @@ -17,6 +17,7 @@ use Filament\Support\Enums\ActionSize; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Support\Facades\Auth; use Livewire\Attributes\Url; use Livewire\Component; @@ -49,8 +50,11 @@ public function addToCategoryAction(): Action TextInput::make('label') ->required($category->postes->count() == 0) ->maxLength(255), + Select::make('user_id') + ->relationship(name: 'user', titleAttribute: 'name') + ->default(Auth::id()) + ->required(), ]; - // TODO : insert in 2nd place if ($category->postes->count() > 0) { $select = Select::make('poste_id') ->required() @@ -91,8 +95,10 @@ public function editNoteAction(): Action TextInput::make('label') ->required($category->postes->count() == 0) ->maxLength(255), + Select::make('user_id') + ->relationship(name: 'user', titleAttribute: 'name') + ->required(), ]; - // TODO : insert in 2nd place if ($category->postes->count() > 0) { $select = Select::make('poste_id') ->required() @@ -106,15 +112,15 @@ public function editNoteAction(): Action ->icon('heroicon-m-pencil-square') ->iconButton() ->modalFooterActions(fn (Note $record, Action $action) => [ + $action->getModalSubmitAction(), + $action->getModalCancelAction(), DeleteAction::make() ->requiresConfirmation() ->record($record) ->cancelParentActions() ->extraAttributes([ - 'class' => 'me-auto', + 'class' => 'ms-auto', ]), - $action->getModalCancelAction(), - $action->getModalSubmitAction(), ]); } diff --git a/app/Models/Note.php b/app/Models/Note.php index 7b07aab..17a9592 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -31,4 +31,9 @@ public function poste(): BelongsTo { return $this->belongsTo(Poste::class); } + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } }