如何在Laravel中获取关系模型的当前页面标题?
我的数据库表中有一些字段,我想根据每页显示如何在Laravel中获取关系模型的当前页面标题?,laravel,eloquent,laravel-6,laravel-6.2,Laravel,Eloquent,Laravel 6,Laravel 6.2,我的数据库表中有一些字段,我想根据每页显示标题、说明和关键字,请告诉我如何显示这些字段。我的数据库字段名称是metatitle,metadesc,关键字 这是我显示属性列表的控制器代码 public function listtype($slug){ $prtype= Listing::whereHas('proType',function($q) use($slug){ $q->where('slug','like','%'.$slug.'%');
标题
、说明
和关键字
,请告诉我如何显示这些字段。我的数据库字段名称是metatitle
,metadesc
,关键字
这是我显示属性列表的控制器代码
public function listtype($slug){
$prtype= Listing::whereHas('proType',function($q) use($slug){
$q->where('slug','like','%'.$slug.'%');
})->paginate(50);
return view('property-type',compact('prtype','title'));
}
您可以通过以下方式进行操作:
public function listtype($slug){
$prtype= Listing::whereHas('proType',function($q) use($slug){
$q->where('slug','like','%'.$slug.'%');
})->with('proType')->paginate(50);
dd($prtype); /** for checking **/
return view('property-type',compact('prtype', $prtype));
}
您可以通过以下方式进行操作:
public function listtype($slug){
$prtype= Listing::whereHas('proType',function($q) use($slug){
$q->where('slug','like','%'.$slug.'%');
})->with('proType')->paginate(50);
dd($prtype); /** for checking **/
return view('property-type',compact('prtype', $prtype));
}
您的列表模型是否有
metatitle、metadesc、关键字
字段?我想从这个proType
中获取标题,我可以从列表
模型中轻松获取标题。但是我很难从porType`@saini获得标题,或者您可以使用with()
方法。您的列表模型是否有元标题、元描述、关键字
字段?我想从这个proType
获得标题,我可以从列表
模型轻松获得标题。但是我很难从
porType`@saini获得标题,或者您可以使用with()
方法。谢谢兄弟。。你太棒了…你解决了我的问题…我从过去5个小时就被困在这里面了。谢谢兄弟。。你太棒了…你解决了我的问题…我从过去5个小时就被困在这里面了。