Multiple things to one query

Posted 6 months ago by kennybjr87

Looking for some advice / proper way to handle doing multiple things to one query so, for example, lets say I have a table called Events on the dashboard I need to do two things I need to first count the total number of events so I can display that to my view but I also need to only display these events that are coming up not the past dates on the same controller. which would obviously be a where clause so without doing multiple queries for the same table how could I split this up? I have tried something like this.

    $events = Events::where('user_id', Auth::user()->id);

    //do whatever I need to here first as in count results

    //then my where to display only upcoming events nothing in the past
     $events->where('end_date', '>=', Carbon::today()->toDateString())->paginate(15);

but I get an appends error trying to display that to my view

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

Reply to

Use Markdown with GitHub-flavored code blocks.