I have a problem with ordering records from a pivot table. I have three tables (many-to-many relationship) like this :
menu
id
name
page
id
name
menu_page
id
name
order
menu_page_id
menu_id
page_id
How can I get all the records from the the pivot table (menu_page) ordered by the "order" attribute using Eloquent ?
I finally find a way to get what I need with this method in my Menu Controller :
public function menu_page () {
return $this->belongsToMany('Page', 'menus_pages')->withPivot('id', 'name', 'order', 'menu_page_id')->orderBy('order', 'asc');;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With