laravel orderBy id works fine with this function:
News::orderBy('id', 'desc')->paginate(20);
But I'm struggling to achieve this with a custom field.
My custom date field (sorting) is a jQuery UI datepicker field that fills a chosen date and it's in this format:
yy-mm-dd
so, if I choose from the datepicker let's say today it will be displayed as a 2017-12-05 and that saves in the database in a same format.
The reason for using this custom field is to add a old news articles, but in a different order.
I've tried to do this with:
News::orderBy('sorting', 'desc')->paginate(20);
but this error is displayed:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'sorting' in 'order clause' (SQL: select * from `news` order by `sorting` desc limit 20 offset 0)
That column does exists in my database.
How can I order my created articles using my custom "sorting" date field in Laravel?
EDIT:
This is the function for the news lists:
public function newsList() {
$news = News::orderBy('id', 'desc')->paginate(20);
return view('news-list', compact('news'));
}
As I mention before this works, but the idea is to order by a custom date field.