Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tomasosho's avatar

get date data from with one to many relationship and filter by date

I have multiple relationships and i want to select get the relationship data``` and compare it to the current date```` in my query.

Query

$workflow = Workflow::with('cropp', 'work.active')->whereDate('work.date', '>', Carbon::now())->get();

Workflow Model

public function work()
    {
        return $this->hasMany(Stage::class, 'workflow', 'id');
    }

Stage Relationship

public function active()
    {
        return $this->hasOne(Activity::class, 'stages', 'id');
    }
0 likes
1 reply

Please or to participate in this conversation.