私はブレードビューで雄弁な関係から日付を渡そうとしていますが、上記のエラーが発生しています。私はこの場合と同様の質問を見つけることができませんでした。ここで私は私が持っている、これまで行われてきたものだ次のモデル私はこのプロパティ[日付]がこのコレクションインスタンスに存在しません
public function index()
{
$products = Product::with('prices')->orderBy('id')->get();
$prices = Price::all()->groupBy('date');
return view('home', compact('products', 'prices'));
}
ように私のコントローラにデータを渡している
class Price extends Model
{
protected $guarded = ['id'];
public function product()
{
return $this->belongsTo(Product::class, 'product_id');
}
}
製品
class Product extends Model
{
protected $guarded = ['id'];
public function prices()
{
return $this->hasMany(Price::class, 'product_id');
}
}
価格そして、これは私の見解のコードです。
@foreach($prices as $price)
<div class="panel panel-default">
<div class="panel-heading">
{{ $price->date }}
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Difference</th>
<th>Percentage</th>
</tr>
</thead>
<tbody>
<tr>
@foreach($price->product as $product)
<td>{{ $product->name }}</td>
@endforeach
<td>{{ $price->cost }}</td>
<td>0</td>
<td>0</td>
</tr>
</tbody>
</table>
</div>
@endforeach
私は逃したと私はどのように私のコードを動作させるのですか?
あなたの価格モデルの日付属性がありますか? – unreleased
はい、価格表の列はid、product_id、日付とコストです – Mena