Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从数据库Laravel在视图中显示数据_Laravel_Laravel Blade - Fatal编程技术网

从数据库Laravel在视图中显示数据

从数据库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

所以我有两张桌子:

订单

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(){
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 }};
  }
 }