@gabriel27 as you said what you need is to get all photo albums that are allocated to a certain user. If u need to get all the photo album belonging to a certain User just do the inverse of the relation in the User model is the same as getting all the users belonging to a photo album
public function photoAlbums()
{
return $this->belongsToMany(PhotoAlbum::class);
}
then get the users photos
User::find(5)->photoAlbums;
also if the relation is many to many be sure to follow Laravel convention and name your relations methods plurals. If i need to apply a condition on the pivot table
$id = 5;
PhotoAlbum::whereHas('users', function (Builder $query) use ($id){
$query->where('photo_album_user.[some_column]',$id);
})->get();
But you don't need it in this case since u set the relation in the model and you don't have any additional info on the pivot table