7 months ago

how to write this mysql query using eloquent?

Posted 7 months ago by alihoushyaripour

Hi, I have a model with name Game and I want to write a eloquent query with multiple Date where, I was write this query as raw but can't write it using eloquent to fetch data as model.

game model class:

    // other parameters
    timestamp created_at;
    timestamp updated_at;
    timestamp started_at;
    timestamp finished_at;
    timestamp deleted_at;

php code and mysql query:

$now = \Carbon\Carbon::now()->format('Y-m-d H:i:s');
$afterTomorrow = \Carbon\Carbon::today()->addDays(2)->format('Y-m-d H:i:s');
\DB::raw("select * from games where ( started_at >= $now and started_at <= $afterTomorrow ) or ( started_at <= $now and finished_at >= $now )")->getValue();

Anyone can help me?

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