Php Laravel-对非对象调用成员函数get() @foreach($wishItems作为$wishItem) @foreach($products as$product) @如果($product->id==$wishItem->product\U id) 名称: 价格:{{$product->Price}}欧元 @恩迪夫 @endforeach @endforeach
Php Laravel-对非对象调用成员函数get() @foreach($wishItems作为$wishItem) @foreach($products as$product) @如果($product->id==$wishItem->product\U id) 名称: 价格:{{$product->Price}}欧元 @恩迪夫 @endforeach @endforeach,php,laravel,laravel-4,Php,Laravel,Laravel 4,$wishItems是发送到此视图的var,可以$products=Product::find($wishItem->Product_id)->get()这里我有问题。。我得到错误:调用非对象上的成员函数get()。。。。我试图用数字替换$wishItem->product\u id,例如3[它存在于数据库中],但同样…假设您有一个wishItem和产品型号 @foreach ($wishItems as $wishItem) <?php $products = Product::
$wishItems
是发送到此视图的var,可以$products=Product::find($wishItem->Product_id)->get()代码>
这里我有问题。。我得到错误:调用非对象上的成员函数get()
。。。。我试图用数字替换$wishItem->product\u id
,例如3
[它存在于数据库中],但同样…假设您有一个wishItem和产品型号
@foreach ($wishItems as $wishItem)
<?php $products = Product::find($wishItem->product_id)->get(); ?>
@foreach($products as $product)
@if($product->id == $wishItem->product_id)
Name: <a href="{{ URL::route('product', $product->id) }}"> {{ $product->title }} </a><br>
Price: {{ $product->price }} €<br>
<hr>
@endif
@endforeach
@endforeach
在你看来
class WishItem extends Eloquent {
public function product()
{
return $this->hasOne('Product');
}
}
更多信息:
我想你真正想要的是:
$product = $wishItem->product;
@foreach($wishItems作为$wishItem)
名称:
价格:{{$product->Price}}欧元
@endforeach
您的
$wishItem
实际上只引用单个产品,因此无需查询集合并执行循环。当我删除get时,我得到了以下信息:为foreach()提供的参数无效试图获取非object的属性是否会在$wishItem->product\u id
或从$product
上引发错误。从product。。。我还试图用数字替换$wishItem->product\u id,但它是sameTryproduct::findOrFail($wishItem->product\u id)
或您的数字,如果失败,这意味着无法找到具有该id的产品我得到了它。。。是 啊我希望列出我有产品标识3的表。。。在产品表中,我还没有得到它…:D谢谢
@foreach ($wishItems as $wishItem)
<?php $product = Product::find($wishItem->product_id); ?>
Name: <a href="{{ URL::route('product', $product->id) }}"> {{ $product->title }} </a><br>
Price: {{ $product->price }} €<br>
<hr>
@endforeach