dimanche 7 février 2021

Relation not working properly using in Laravel

I have a Post table that contains posts and media_images contains images related to a specific post. This is the relation that i'm using but in present scenario if post does not have image then no post is returned but i want to return post also when there in no image.

  $where[] = ['category_id', '=', $request->category_id];
            return Posts::where($where)->with('media_images', 'category')->WhereHas('media_images', function ($query) use ($media_id) {
                if (!empty($media_id)) {
                    $query->InMediaId($media_id);
                } 
            })->paginate(10);


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire