php - Laravel 5.4 Eloquent where parent -
so have 2 models setup, user , post. post has belongsto setup of user , user has hasmany setup posts.
when getting posts, want make sure user isn't banned. banned int in database in column called ban , want make sure it's equal 0. looped through posts, checked make sure user wasn't banned , pushed array , passed array view working fine. however, want enable paginate , it's broken because i'm not passing in eloquent object.
here eloquent right now:
$posts = post::where('status', '>', 1)->orderby('published_date', 'desc')->paginate(10);
use wherehas()
$posts = post::where('status', '>', 1)->wherehas('user', function($q) { $q->where('ban', 0); })->orderby('published_date', 'desc')->paginate(10); i assume, have user relation on user model post model.
Comments
Post a Comment