orWhere Hey guys, I am trying something like this:
$today = strToLower(now()->format('l'));
$posts = auth()->user()->posts()->latest()->where($today,'<>',0)->orwhere('immer','=','1')->paginate(10);
return view('posts.index')->with('posts', $posts);
What is happening is now that the first where the statement works fine. I only get the posts from the specific user. But the second where clause gives back all tables with the name 'immer' with the value 1 from All users.
Does anyone have any idea how to fix this?
OK nice. But I get the error "Undefined variable: today".
So somehow it can't find my defined
$today = strToLower(now()->format('l'));
variable now.
My whole function looks like this:
public function index()
{
$today = strToLower(now()->format('l'));
$posts = auth()->user()->posts()
->latest()
->where(function($query) {
$query->where($today,'<>',0)
->orwhere('immer','=','1');
})
->paginate(10);
return view('posts.index')->with('posts', $posts);
}
You need to pass that variable like this
function($query) use ($today) {
please mark it solved if it is?
Please sign in or create an account to participate in this conversation.