Laravel 5.1 - Order By Two Columns Not Working As Intended
I have two columns, quarter_number and quarter_year. The quarter_number column stores a value between 1 and 4, while quarter_year stores a year value. I want the data to be sorted like so for example:
ex: (quarter_number - quarter_year) 4 - 2015 3 - 2015 2 - 2015 1 - 2015 4 - 2014 3 - 2014 etc...
Thus it seemed like this statement would work:
$last_figures = QuarterData::where('company_id', '=', $company->id)
Unfortunately, it doesn't seem to work as intended (which I thought would be similar to a radix sort). It ends up just sorting by the year (or whatever to last orderBy statement is). Do I have to just program my own custom radix sort for this? Or is there a better way?
I think you have to use the
quarter_year first, like this:
$last_figures = QuarterData::where('company_id', '=', $company->id) ->orderBy('quarter_year')->orderBy('quarter_number')->get();
- → I can't do a foreign key, constraint error
- → How to implement DbDongle::convertTimestamps as workaround of invalid timestamps with MySql strict
- → MySQL error "Foreign key constraint is incorrectly formed"
- → Eloquent Multitable query
- → "Laravel 5.1" add user and project with userId
- → Database backup with custom code in laravel 5 and get the data upto 10 rows from per table in database
- → Laravel 5.1 QueryException when trying to delete a project
- → Using Array in '->where()' for Laravel Query Building
- → Chaining "Count of Columns" of a Method to Single Query Builder
- → Laravel Eloquent Joining Strange query
- → convert time using mysql laravel 5
- → How to update a column after an expiration date in MySQL?
- → Foreign key constraint fails on existing key