雄心勃勃的关系与渴望加载

I have the following code to get the final data $result2.

$agent = auth()->user()->id;
$result = App\AgentStatus->select('callId')->where(function($query)use($agent) {
    $query->where('agentId', '=', $agent);
})->first();
$result2 = NULL;
if($result != NULL) {
    $id = $result->callId;
    $calls = App\CallStatus->where(function($query)use($id) {
       $query->where('callId', '=', $id);
    })->first();
    $id = $calls->callerId;
    $result2 = App\Callout->where(function($query)use($id) {
        $query->where('number', '=', $id);
    })->first();
}

Models:

AgentStatus:

protected $primaryKey = 'agentId';

CallStatus

protected $primaryKey = 'callId';

Callout: Primary Key is row id

This is the first project I'm working on with laravel and I wanted to change the above code to something that implements relationship and eager loading. For now it works but it might run too slow when tables have a lot more rows.

Laravel has good documentation

https://laravel.com/docs/5.8/eloquent-relationships

If you have concerns about performance issues you can follow denormalization