if($city!='Others'){
$posts = Post::orderby('id','desc')->where(['city'=>$city])->paginate(10);
}
else{
$posts = Post::orderby('id','desc')->whereNotIn(['city'=>'Lahore'])->paginate(10);
}
}
I have displayed some specific data now I want to display data other than those which were displayed before.
First if is showing normal data and I am trying to display remaining data in else part.
Thank you for all your help. The only thing required was to keep whereNotIn statement values in an array. Like this.
if($city!='Others'){
$posts = Post::orderby('id','desc')->where(['city'=>$city])->paginate(10);
}
else{
$posts = Post::orderby('id','desc')->whereNotIn(['city',array('Lahore')->paginate(10);
}
}
This is a guess based on how your database is setup.
EDIT based on reply (see: https://laravel.com/docs/5.5/queries#where-clauses and Laravel != operator in where not working):
if($company!='Others'){
$posts = Post::orderby('id','desc')->where(['company'=>$company])->paginate(10);
}
else{
$posts = Post::orderby('id','desc')->where('city', '<>', 'Lahore')->paginate(10);
}
Does that help (take a look at the links)?
WhereNotIn
will take array
of value You also need to pass column name in it
if($city !='Others'){
$posts = Post::orderby('id','desc')->where(['city'=>$city])->paginate(10);
}
else{
$posts = Post::orderby('id','desc')->whereNotIn('city',['Lahore'])->paginate(10);
}