P
P
Pavel Konchich2021-01-17 21:12:43
Laravel
Pavel Konchich, 2021-01-17 21:12:43

Sort data for today only Laravel 8 - how?

Good afternoon. There is a conditional database - sessions with the last_activity date. It is

necessary to display in the blade only the data received for today.

Code for getting data from the sessions table:

$sessionDataActivityALl = DB::table('sessions')
                                ->select('last_activity')
                                ->get();


$newVisitsToday = $sessionDataActivityALl->count();


how to sort this data only for today?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-01-18
@konchychp

DB::table('sessions')
    ->select('last_activity')
    ->whereDate('last_activity', today())
    ->get();

but if you just count, then you don’t need to create a collection (count on request)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question