Im am using laravel 7. I have 2 tables, products and testimonials. Each testimonial is related to a product. So i made an 2 relationships:
- Product: hasMany('App\Models\OM\Testimonial');
- Testimonial: belongsTo('App\Models\OM\Product', 'product_id')
But when i dd(Testimonial->with('product)) i get this
array:1 [▼ "testimonials" => Illuminate\Database\Eloquent\Builder {#347 ▼ #query: Illuminate\Database\Query\Builder {#358 ▶} #model: App\Models\OM\Testimonial {#359 ▼ #table: "om_testimonials" #fillable: array:4 [▶] #connection: null #primaryKey: "id" #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: false +wasRecentlyCreated: false #attributes: [] #original: [] #changes: [] #casts: [] #classCastCache: [] #dates: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #guarded: array:1 [▶] } #eagerLoad: array:1 [▶] #localMacros: [] #onDelete: null #passthru: array:19 [▶] #scopes: [] #removedScopes: [] } ]
Testimonial::with('product')->get();
this would work – Akhtar Munir