我在我的数据库中创建了一个控制菜单,但是现在我需要在同一页面中列出它。
use Illuminate\Support\Facades\DB;
class ControllerPageViews extends Controller {
public function home(){
$menus = DB::select('select * from menus');
return view('index')->with('menus', $menus);
}
public function comofunciona(){
$menus = DB::select('select * from menus');
return view('como-funciona')->with('menus', $menus);
}
public function especialidades(){
$menus = DB::select('select * from menus');
return view('especialidades')->with('menus', $menus);
}
public function exames(){
$menus = DB::select('select * from menus');
return view('exames')->with('menus', $menus);
}
public function medicamentos(){
$menus = DB::select('select * from menus');
return view('medicamentos')->with('menus', $menus);
}
public function solicitarconsulta(){
$menus = DB::select('select * from menus');
return view('solicitar-consulta')->with('menus', $menus);
}
public function contatos(){
$menus = DB::select('select * from menus');
return view('contatos')->with('menus', $menus);
}
}
我之后使用elloquent,但现在,可以在同一页面导入2个列表吗?
答案 0 :(得分:1)
使用紧凑型
public function contatos(){
$menus = DB::select('select * from menus');
$menus2 = DB::select('select * from menus2');
return view('contatos',compact('menus','menus2'));
}
然后在视图上:
@foreach($menus as $menu)
{{ $menu->field_name }}
@endforeach
@foreach($menus2 as $menu2)
{{ $menu2->field_name }}
@endforeach