Skip to content

Commit

Permalink
Implement AlbumObserver for Album and User interaction
Browse files Browse the repository at this point in the history
This commit adds AlbumObserver to manage User and Album interaction in the application. Now, if any user is creating or updating an album, their user_id is automatically stored in the Album model, creating a way to track the relationship between the user and their albums.
  • Loading branch information
marco-introini committed Dec 21, 2023
1 parent da9b646 commit 2387d08
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/Observers/AlbumObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Observers;

use App\Models\Album;

class AlbumObserver
{
public function creating(Album $album): void
{
if (auth()->check()){
$album->user_id = auth()->id();

Check failure on line 12 in app/Observers/AlbumObserver.php

View workflow job for this annotation

GitHub Actions / laravel-tests

Property App\Models\Album::$user_id (int) does not accept int|string|null.
}
}

public function updating(Album $album): void
{
if (auth()->check()){
$album->user_id = auth()->id();

Check failure on line 19 in app/Observers/AlbumObserver.php

View workflow job for this annotation

GitHub Actions / laravel-tests

Property App\Models\Album::$user_id (int) does not accept int|string|null.
}
}
}

0 comments on commit 2387d08

Please sign in to comment.