Я пытаюсь отобразить поля из нескольких таблиц в одну таблицу HTML в соответствии с соответствующими данными в блейде.Но я не получаю никакого результата
Мой дизайн базы данных:
District
| id
| district_name
Municipal
| id
| district_id
| Municipal_uid
| municipal_name
Area
| id
| area_name
| district_id
| municipal_id
Это то, чего я пытаюсь достичь,
Area ID | Area Name | District Name | Municipal Name | municipal UID
Моя модель
Площадь:
public function districts(){
return $this->belongsTo('App\Districts');
}
public function municipals(){
return $this->belongsTo('App\Municipals');
}
Муниципальный:
public function district(){
return $this->belongsTo('App\Districts');
}
public function approvedlayout(){
return $this->hasMany('App\Approvedlayouts');
}
Район:
public function municipal(){
return $this->hasMany('App\Municipals');
}
public function approvedlayout(){
return $this->hasMany('App\Approvedlayouts');
}
blade
<table class="table table-striped">
<thead class="text-center">
<tr>
<th>Area ID</th>
<th>Area Name</th>
<th>District Name </th>
<th>Municipal Name</th>
<th>Municipal UID</th>
</tr>
</thead>
<tbody class="list">
@foreach ($areas as $layout)
<tr>
<td>{{$layout ->id}}</td>
<td> {{ $layout-area_name }}</td>
<td> {{ $layout->districts-> district_name }}</td>
<td> </td>
<td></td>
<td></td>
</tr>
@endforeach
</tbody>
</table>
{{$areas-> links()}}
Контроллер
public function index()
{
$areas = Area::simplePaginate(5);
return view('admin.area.index',compact('areas'));
}
Когда я пытаюсь отобразить название района
({{$ layout-> distric-->district_name}})
Я получаю сообщение об ошибке,
Пытается получить свойство 'district_name' необъекта (Просмотр: lapp / resources / views / area / index.blade.php