public function selfattribute()
{
return $this->belongsToMany("Selfattribute",'cars_selfattribute','selfattribute_id','cars_id');
}
public function carsimg()
{
return $this->hasMany('Carsimg');
}
public function member()
{
return $this->belongsTo('\app\index\model\Member');
}
同时对应的模型也要建立对应的方法。
在控制器层写方法:
public function lst()
{
$cars_model = model("Cars");
$cars_list = $cars_model->getCarsList();
$this->assign("cars_list",$cars_list);
// dump($cars_list);
return view();
}
其中getCarsList()方法在模型层中实现:
public function getCarsList()
{
$cars_list = Cars::paginate(2)->each(function($value,$key){
$level_find = db("level")->where('id',$value['level'])->value('name');
$value['level_name'] = $level_find;
$value->carsimg;
$value->member;
$value->selfattribute;
});
return $cars_list;
}