Skip to content

Commit

Permalink
feat: Edit Auth in Note (#8)
Browse files Browse the repository at this point in the history
Can modify User in add/edit note
  • Loading branch information
sylfel authored Mar 12, 2024
1 parent 9d1b548 commit 6f40922
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/Livewire/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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(),
]);
}

Expand Down
5 changes: 5 additions & 0 deletions app/Models/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ public function poste(): BelongsTo
{
return $this->belongsTo(Poste::class);
}

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
}

0 comments on commit 6f40922

Please sign in to comment.