lundi 12 février 2018

How to get data of saturday and Sunday in laravel eloquent

I am trying to fetch the data, that are occurring in saturday and sunday from my database. I wrote an eloquent query which i believe is right, but it still doesn't work.

My query is like this

  public function activityFeeds(Request $request){
      $currentDate =  date('Y-m-d');
      $data['activity'] =  Activity::where('deleted_at',NULL)
          ->where('gmt_date_set','>=',$currentDate)
            ->where(\DB::raw( "DAYOFWEEK( `gmt_date_set` )", '=',0 ) )
          ->with('user')
          ->get();
        return json_encode($data);
  }

This is returning empty json even though there are value for saturnday and sunday.

I did check on the google and i found a guy who said this is the way to do, even so i wonder why this is not working .

https://laravel.io/forum/04-29-2015-mysql-dayofweek-in-dbraw

I tried to debug with ->toSql and my query looks like this

"select * from `events` where `deleted_at` is null and `gmt_date_set` >= ? and DAYOFWEEK( `gmt_date_set` ) is null and `events`.`deleted_at` is null"

Can anyone please help me? Thank you :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire