I have a project with laravel 10.45 and livewire 3.
I try to edit an Company but i received this error "Attempt to assign property "id" on null"
My method Update.php have a mount method, like bellow
/** * @throws AuthorizationException */ public function mount(): void { $this->authorize(Can::BE_AN_ADMIN->value); $company = Company::findOrFail(request()->route('id')); $this->setCompany($company); }
I put some dd() in codes and I can saw that the variable $company return the value expected.
I put some dd into setCompany and I can saw that the variable $company return values, normaly.
So, the error said that i’m havent the property "id", like my $company variable is null.
I trying to solve this in diffents ways like put on IF before initialize the method setCompany, the problem is that this if is true
because i have the return inside variable $company.
Please, anyone here had the same problem?
[The dd into function setCompany] https://phpout.com/wp-content/uploads/2024/02/oTGmo.png [Return in browser] https://phpout.com/wp-content/uploads/2024/02/JC2x5.pngI trying to solve this in diffents ways like put on IF before initialize the method setCompany, the problem is that this if is true
because i have the return inside variable $company.
I expected that the setCompany works normally
2
Answers
Thanks Karl Hill,
The same error occurs.
Note: the application is running with Docker and is running normally on another machine with not errors
The
setCompany
method is likely trying to set theid
property on this nullCompany
object, hence the error. To fix this, you should check if the Company object is null before calling thesetCompany
method. H