vendredi 10 mai 2019

Laravel eloquent model where datetime less than or equal

I am having an expire_datetime field in Test model and it has many relationship with Candidate model. I want to get all the tests which exipre_datetime is less than or equeal to now datetime. I am doing like this but I am getting all the records, date comparirion is not functioning.

Test Model:

public function testcandidates()
    {
        return $this->hasMany(Candidate::class,'test_id','id');
    }

My TestController:

$tests = Test::with(
       ['testcandidates' => function ($query) {
           $query->where('result', '=', 'assigned');
        }])
        ->where('expire_datetime', '<=', Carbon::now('UTC'))
        ->get();



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2H6RM4A
via IFTTT

Aucun commentaire:

Enregistrer un commentaire