This error usually occurs when we are trying to call a function that can be accessed via model and accessing with empty results.
dump your results and check you are calling the method addEagerConstraints() from a null value
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to work out what I've done wrong, but I cannot seem to work it out.
I have the following tables;
f_account table --> f_account_status and f_account_type
f_account_status --> f_account_status_id
f_account_type --> f_account_type_id
In my AccountsController I am saying:
public function index()
{
$accounts = Account::with('account_type', 'account_status')->get();
return view('accounts.index', compact('accounts'));
}
And the Account model is:
public function account_status(){
$this->hasOne('App\AccountStatus', 'f_account_status_id');
}
public function account_type(){
$this->hasOne('App\AccountType', 'f_account_type_id');
}
And then the type additional models,
AccountStatus
protected $table = 'f_account_status';
public function account(){
$this->belongsTo(Account::class, 'f_account_status');
}
AccountType
protected $table = 'f_account_type';
public function account(){
$this->belongsTo(Account::class, 'f_account_type');
}
Why do I keep getting an error when trying to retrieve the results?
Please or to participate in this conversation.