Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Can you provide your model relationships and which data from each model your looking for

0

Hi RDelorier,

I've a Category and a Listing model

  1. Category with parent id is Sub Category
  2. Each category has some sub categories
public function children(){
        return $this->hasMany('App\Cat','parent_id')->whereStatus(1);
}
  1. (Sub) category hasMany Listings
public function listings(){
        return $this->hasMany('App\Listing')->whereStatus(1);
}

and 4. in Listing model

public function cat(){
        return $this->belongsTo('App\Cat');
}

Now, when I'm in category, I want to fetch all featured items all of its sub categories. Home this makes sense.

Last updated 9 years ago.
0

See ==http://laravel.io/forum/04-04-2015-looping-through-collection. Plus there are Laracast on this.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.