2

I'm using Backpack for Laravel, Crud module.

How to use orderby() for multiple columns?

example:

$this->crud->orderBy('name','desc')->orderBy('year,'asc');

I have seen the src and the orderby accepts only one parameter.

Any suggestion?

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Wtime
  • 21
  • 1
  • 3
  • Possible duplication of https://stackoverflow.com/questions/17006309/how-to-use-order-by-for-multiple-columns-in-laravel-4 – user115014 Nov 15 '17 at 19:02
  • 5
    Possible duplicate of [How to use order by for multiple columns in laravel 4?](https://stackoverflow.com/questions/17006309/how-to-use-order-by-for-multiple-columns-in-laravel-4) – user115014 Nov 15 '17 at 19:02
  • I'm using Backpack for Laravel, Crud module. – Wtime Nov 16 '17 at 07:51

1 Answers1

0

You should be able to chain any number of orderBy methods to CRUD's query property, which is the actual query that will be executed:

$this->crud->query = $this->crud->query->orderBy('name', 'desc')->orderBy('year', 'asc');
tabacitu
  • 6,047
  • 1
  • 23
  • 37
  • I have "select columns" with relations and they are sorted by id and not by value. I have: `$this->crud->query = $this->crud->query->with(['artista' => function ($query) { $query->orderBy('nome_artista', 'asc'); }])->get();` But I get this error: `SQLSTATE[42S22]: Column not found: 1054 Unknown column 'nome_artista' in 'order clause' (SQL: select * from artisti where artisti.id in (1, 3, 7) order by nome_artista asc)` Eager loading does'nt work. – Wtime Nov 18 '17 at 12:05