Normally you will have an model object returned, you must have something in your model that changing the default behavior.
Please post the complete code of the Sensor and Equipement models.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have three tables : sensors, equipement, location
In sensor Table, I have
public function equipement()
{
return $this->belongsTo(Equipement::class);
}
In Equipement table, I have
public function location()
{
return $this->belongsTo(Location::class);
}
What I would like to do is returning in one query all the informations regarding the sensor + the equipement association and the location associated to this equipement.
I did something like
public function all()
{
$sensors = Sensor::with('equipement', 'equipement.location')->get();
return $sensors;
}
It seems to works. However, when I want to loop in Blade, the equipement and location are not objects but array.
@foreach ($sensors as $sensor)
<tr>
<td>{{ $sensor->id }}</td> //Working
<td>{{ $sensor->device_number }}</td> //Working
<td>{{ $sensor->installation_date }}</td> //Working
<td>{{ $sensor->equipement->name}}</td> //This is not working. I need instead to do $sensor->equipement['name']
<td>{{ $sensor->equipement->location->name}}</td> //This is not working.
</tr>
In Tinker, when I do
$sensors = Sensor::with('equipement', 'equipement.location')->first();, I'm able to access as an object the attribute of the equipement and the location.
I know, I'm getting the object with first() but with get(), as I loop, it should be the object as well no ?
Could you please help me ?
In Blade, I would like to access attributes as an object and not array. Thank you.
Please or to participate in this conversation.