Support the ongoing development of Laravel.io →
Database Eloquent

I would like to sort items by column relation in laravel (5.1)

I have a database table called interests, with a column called 'town_searched' and I would like to sort interests by town_searched in my view

When I have all interests, How can I order by town_searched ?

Example of the result I want in my view :

In the town of Sydney :

  • Interest
  • Interest

In the town of New-York :

  • Interest
  • Interest

My controller :

$userid = \Auth::id();
$interests = DB::table('interests')
    ->where('user_id', $userid)
    ->groupBy('town_searched')
    ->get();

Thanks for your help ! :)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Rayzor286 rayzor286 Joined 23 Mar 2016

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.

© 2025 Laravel.io - All rights reserved.