#Attempt to read property service_status_id on null
63 messages · Page 1 of 1 (latest)
Show the whole error, it sounds like you're probably trying to read a value on a relationship without loading said relationship.
But when I delete the last instance it works very well
The controller can read the relationship
so I don't understand, I check some forum and it said that the php version is the problem
The error isn't saying service_status_id is null, it is saying whatever you're trying to check that variable on is null.
Show the whole error.
oooooh ok
[2022-10-13 20:21:54] local.ERROR: Attempt to read property "service_status_id" on null (View: /home/bujiybc/hopassist/resources/views/admin/Service/dashboard.blade.php) {"view":{"view":"/Service/dashboard.blade.php","data":{"errors":"<pre class=sf-dump id=sf-dump-2021905783 data-indent-pad=" "><span class=sf-dump-note>Illuminate\Support\ViewErrorBag</span> {<a class=sf-dump-ref>#1759</a><samp data-depth=1 class=sf-dump-expanded>
#<span class=sf-dump-protected title="Protected property">bags</span>: []
</samp>}
So it sounds like serviceTracking relationship isn't loaded. Check out https://laravel.com/docs/9.x/eloquent-relationships#eager-loading
But why is the relationship is load before ?
I don't understand your question, sorry.
I already have data in the database Service and ServiceTracking, and the relation is load in the view
but now when I create a new Service I have this problem
I already create 4 Services and never have this problem
Did those services all have ServiceTracking relationships? Maybe the problem is that the service you're adding is missing a serviceTracking relationship and you're not checking if the relationship exists before trying to access a field on it.
Yes they all have a ServiceTracking
Adjust your code to instead be
@foreach ($services as $service_wait)
@if ($service_wait->serviceTracking && $service_wait->serviceTracking->service_status_id == 1)
But they have a ServiceTracking
it's required when create a Servic
ServiceTracking Model have this
That isn't serviceTracking .. that is serviceStatus
In the ServiceTracking Model I load service status
The problem isn't your serviceTracking -> serviceStatus relationship. It is service -> serviceTracking relationship either not existing or not being loaded.
oh okay
public function serviceTracking()
{
return $this->hasOne(ServiceTracking::class);
}
I have this
That defines the relationship, but that doesn't mean it is loaded when you grab the service.
Take a look at the eagerloading documentation I posted.
It is load because old Service work well
I can see it at the view so the relation is load
it's just now when I create a new one
Are you sure you're creating the relationship when you create a new one?
Show
All Services have ServiceTracking
So when I delete the last one all works very well
I delete the last Service, the last ServiceTracking etc ..
Show the services too.
Show your new one that is breaking it.
Can you show your controller code?
I think the problem is from the server maybe I'm not sure
@if(!$service_wait->serviceTracking)
dd($service_wait)
@endif
Thanks you very much for the help ! very very much I'm very in panic
Add that inside your foreach, show me which service is failing.
okay
Undefined property: Illuminate\Pagination\Paginator::$serviceTracking
I have this error
Eh? Show me the code with my update
yes I do it
Actually might be better to just dump the contents of $services in your controller and show me the output.
Okay !