Error 'trying to get property of non object' when updating a resource on which Heading Field displays a queried value involving a pivot
- Laravel Version: 6.0.4
- Nova Version: 2.3.1
- PHP Version: 7.3.3
- Database Driver and Version: 10.1.38-MariaDB
- Operating System and Version: Windows 10 version 1809
- Browser type and version: Google Chrome 77.0.3865.90
Description
When the Heading field uses a database query with pivot in its argument the value is displayed fine but on update the system returns 'trying to get property of non object' error. This also appears to affect other fields which can use query results in their methods, e.g. help.
Steps To Reproduce
I have the following line in my Nova resource:
BelongsToMany::make('Authorities')
->fields(function ()
{
return [
Heading::make('Your limit for this purchase is ' . $this->displayLimit() . ' .'),
...
The function is defined as follows:
public function displayLimit()
{
$id1 = DB::table('delegations')->where('user_id', auth()->user()->id)->value('id');
$id2 = $this->pivot->authority_id;
return DB::table('authority_delegation')->where('delegation_id', '=', $id1)->where('authority_id', $id2)->value('delegated_limit');
}
If I replace $id2 with a number (e.g. 26) everything works. This issue seems to be similar to the previously resolved issue here: https://github.com/laravel/nova-issues/issues/1316
In the meantime, any help on working around this problem would be greatly appreciated. This is critical for my project.
To update, getting an array $id2 = $this->pivot['authority_id']; solves this issue.