-1
  • Vender hasMany Banquet

Here is my query:

$banquet = Vendor::with(['banquet' => function($query){
         $query->where('active',1)->where('id' ,1)->first();
      }])->findOrfail(1);

but the relation part return an collection like get() method not first()

#relations: array:1 [▼
    "banquet" => Collection {#283 ▼
      #items: array:1 [▼
        0 => Banquet {#285 ▼

How to trans like this? So that I can just get the banquet data like $vendor->banquet not $vendor->banquet[0]

#relations: array:1 [▼
   "banquet" => Banquet {#285 ▼
Fan
  • 1,124
  • 3
  • 17
  • 35

1 Answers1

0

I think, you are using OneToMany for banquet.
So, you are getting in the collection/array.

Please, try it as OneToOne. and say if you get any change or not.

return $this->belongsTo();

in banquet method.

or

return $this->hasOne();
Rama Durai
  • 740
  • 6
  • 17