Q:

In Laravel 6, how do I query a model based on the properties of its parent?

Each Project has many Tasks, this is defined in the Project and Task Models.
When opening a Task by browsing to /tasks/{id}, I want to check if it belongs to a Project that is at a specific Stage before I allow the user to open the Task. Looking for something like this, is there a way to do this?
$tasks = Task::where(project->'stage', $current_stage)->where('id', $id)->get();

A:

You should name your variable $task and use first() because when matching ID, there should only be one answer.
$task = Task::with('project')->firstOrFail($id);

if($task->project->stage != $current_stage) {
   // throw your error here, return redirect or whatever
}

