The laravel 6.x returns the output as an array instead of an object when accessing the relationship in one pc it supports the array and on the other pc, it only supports the object.
class Category extends Model
{
public function parent() {
return $this->belongsTo(Category::class,'parent_id');
}
public function children() {
return $this->hasMany(Category::class,'parent_id');
}
}
on the blade page this can be accessed like below
@foreach ($categories as $category)
<tr>
<td >{{$category->parent['name']}}</td>
</tr>
@endforeach
$category->parent->nameand$category->parent['name']are both valid in Laravel; Models are accessible via either syntax, but the preferred method is object access (->).->toArray(). I've never seen the issue with one method of access->namenot working vs the other['name'].