【发布时间】:2019-03-02 11:41:46
【问题描述】:
我的项目中有MyRoom.php 和TotalCity.php,其中每个房间都在一个城市内进行分类
所以我在 MyRoom.php 中这样做了
public function location()
{
return $this->belongsTo(TotalCity::class, 'location_id')->withTrashed();
}
我在 TotalCity.php 中做了这个
public function location()
{
return $this->hasMany(MyRoom::class , 'total_city_id')->withTrashed();
}
我已经用这样的路由和控制器传递了 id 主页.blade.php id)}}">{{ $row->name }}
web.php
Route::get('/city/{id}/rooms/','SiteController@room')->name('room');
站点控制器.php
public function room($id) {
$room = TotalCity::find($id)->location;
return view('frontend.pages.rooms', compact('room'));
}
rooms.blade.php
@foreach($room as $row)
<div class="room">
<a href="{{ route('description',$row->id) }}"><img src="{{ asset(env('UPLOAD_PATH').'/' . $row['photoi1']) }}"/></a>
</div>
@endforeach
但这并没有显示任何城市的任何房间,而我已经在我的数据库中存储了城市和特定城市下的房间。
【问题讨论】: