从数据库Laravel在视图中显示数据
所以我有两张桌子: 订单 id |时间|膳食| id |蔬菜 1 | 12:00 | 1 | 0 成分 id |值|膳食| id 1 |奶酪| 1 2 |牛肉| 1 其中,配料id是指像肉这样的配料类型。 我想在订单视图中显示数据,但我不知道如何显示配料的价值 这是我订购的型号从数据库Laravel在视图中显示数据,laravel,laravel-blade,Laravel,Laravel Blade,所以我有两张桌子: 订单 id |时间|膳食| id |蔬菜 1 | 12:00 | 1 | 0 成分 id |值|膳食| id 1 |奶酪| 1 2 |牛肉| 1 其中,配料id是指像肉这样的配料类型。 我想在订单视图中显示数据,但我不知道如何显示配料的价值 这是我订购的型号 public function ingredients(){ return $this->hasMany(ingredient::class); } 成分模型 public function order(){ r
public function ingredients(){
return $this->hasMany(ingredient::class);
}
成分模型
public function order(){
return $this->hasMany(order::class);
}
和订单控制员
public function show(){
$orders = order::where('vege', 0)->get();
return view('home', ['orders' => $orders]);
}
public function show(){
$orders = order::where('vege', 0)->get();
return view("home",compact('orders'));
}
谢谢您的建议。为了订购模型,请与配料建立关系
public function ingredients()
{
return $this->hasMany('App\Order', 'order_id' ,'id');
}
$orders = Orders::with('ingredients')->where('vege',0)->get();
return view('home',compact('orders'));
您必须在配料顺序\u id中有一个字段
然后你就可以点配料了
public function ingredients()
{
return $this->hasMany('App\Order', 'order_id' ,'id');
}
$orders = Orders::with('ingredients')->where('vege',0)->get();
return view('home',compact('orders'));
在主视图中,您可以轻松地
foreach($orders as $order){
foreach($order->ingredients as $i){
echo $i->id;
}
}
为了使订单模型与配料建立关系
public function ingredients()
{
return $this->hasMany('App\Order', 'order_id' ,'id');
}
$orders = Orders::with('ingredients')->where('vege',0)->get();
return view('home',compact('orders'));
您必须在配料顺序\u id中有一个字段
然后你就可以点配料了
public function ingredients()
{
return $this->hasMany('App\Order', 'order_id' ,'id');
}
$orders = Orders::with('ingredients')->where('vege',0)->get();
return view('home',compact('orders'));
在主视图中,您可以轻松地
foreach($orders as $order){
foreach($order->ingredients as $i){
echo $i->id;
}
}
订单管理员
public function show(){
$orders = order::where('vege', 0)->get();
return view('home', ['orders' => $orders]);
}
public function show(){
$orders = order::where('vege', 0)->get();
return view("home",compact('orders'));
}
主视图
foreach($orders as $order){
foreach($order->ingredients as $i){
echo {{ $i->id }};
}
}
订单管理员
public function show(){
$orders = order::where('vege', 0)->get();
return view('home', ['orders' => $orders]);
}
public function show(){
$orders = order::where('vege', 0)->get();
return view("home",compact('orders'));
}
主视图
foreach($orders as $order){
foreach($order->ingredients as $i){
echo {{ $i->id }};
}
}