1 year ago

How to make a query to filter with a pivot table & another table in Laravel 5?

Posted 1 year ago by Edris899

Hi there,

Sorry for the title I really don't know what to call it.

I am building a illustration website with albums. A illustration can be uploaded to a album.

In the photos table I have a processed table in it. This way I can check if the illustration was processed or not, if yes then it can be searchable if not then the user must edit the processed illustration or illustrations.

I can select the photos in the specific album but I don't know how to filter with the processed illustration belonging to the viewing album.

Also I have a seperate table album_photos table. The relation of a album and a photo is hasMany and belongsToMany.

This way I select all the photos but not filtered with processed or not.

        $photos = Photo::whereIn('id', $album -> album_photos() -> pluck('photo_id'))->get();

And this way I select all the processed photos of the corresponding user.

        $photosNotProcessed = Photo::where('user_id', Auth::user() -> id)->whereNull('processed')->get();

Now I want to select the photos in the viewing album that is not been processed. Any ideas?

Thanks in advance.

Please sign in or create an account to participate in this conversation.