【发布时间】:2020-08-27 22:57:13
【问题描述】:
我正在使用 laravel 7。我有 2 个表格、产品和推荐。每个推荐都与产品相关。所以我建立了两个关系:
- 产品:hasMany('App\Models\OM\Testimonial');
- 客户评价:belongsTo('App\Models\OM\Product', 'product_id')
但是当我 dd(Testimonial->with('product)) 我得到这个
array:1 [▼ “推荐” => Illuminate\Database\Eloquent\Builder {#347 ▼ #query: Illuminate\Database\Query\Builder {#358 ▶} #model: App\Models\OM\Testimonial {#359 ▼ #table:“om_testimonials” #fillable: 数组:4 [▶] #连接:空 #primaryKey:“ID” #keyType:“整数” +递增:真 #和: [] #withCount: [] #perPage: 15 +存在:假 +wasRecentlyCreated: 假 #属性: [] #原版的: [] #变化: [] #casts:[] #classCastCache:[] #日期: [] #dateFormat:空 #追加:[] #dispatchesEvents:[] #observables:[] #关系:[] #触摸:[] +时间戳:真 #隐藏:[] #可见的: [] #guarded:数组:1 [▶] } #eagerLoad:数组:1 [▶] #localMacros:[] #onDelete:空 #passthru:数组:19 [▶] #范围:[] #removedScopes: [] } ]
【问题讨论】:
-
Testimonial::with('product')->get();这会起作用
标签: php laravel eloquent eloquent-relationship