Laravel 雄辩的带垃圾的返回空值
我正在循环浏览一些订单项目,如下所示:Laravel 雄辩的带垃圾的返回空值,laravel,eloquent,Laravel,Eloquent,我正在循环浏览一些订单项目,如下所示: @foreach($order->items as $item) @if ($item->product) <span>{{ $item->product->id }}</span> @elseif ($item->productWithTrashed) <span>{{ $item->productWithTrashed->id }}</span> @endif @
@foreach($order->items as $item)
@if ($item->product)
<span>{{ $item->product->id }}</span>
@elseif ($item->productWithTrashed)
<span>{{ $item->productWithTrashed->id }}</span>
@endif
@endforeach
产品模型包含以下内容:
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
use SoftDeletes;
}
我有什么遗漏吗?你能分享控制器代码吗?还添加了
订单
、项目
和产品
之间关系的说明。
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
use SoftDeletes;
}