Answer the question
In order to leave comments, you need to log in
What is the best way to sort entries alphabetically?
I use this code and it works great.
But a bit not as I need (
public function onRun ()
{
$this->authors = $this->loadAuthors();
}
protected function loadAuthors()
{
$query = AppAuthor::all();
if ($this->property('sortOrder') == 'name asc') {
$query = $query->sortBy('name');
}
if ($this->property('sortOrder') == 'name desc') {
$query = $query->sortByDesc('name');
}
if ($this->property('results') > 0) {
$query = $query->take($this->property('results'));
}
return $query;
}
Answer the question
In order to leave comments, you need to log in
Did it like this:
protected function loadAuthors(){
$table = New AppAuthor;
$table = $table->table;
$query = DB::select("
select *
from {$table}
ORDER BY
name < 'а', //русская
name < 'a', //английская
name < '0',
name");
if($this->property('results') > 0) {
$query = $query->take($this->property('results'));
}
return $query;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question