Given that you're sorting episodes, couldn't you just sort on release date instead of a serial number?
I don't think it will be easy to implement a natsort method for Eloquent as it will be dependent on the database that's used.
Hi,
I have some data for a SelectBox which I need to be sorted naturally.
With orderBy I got 1.01, 10.01, 2.01 but I'll need 1.01, 2.01, 10.01
Is there a way I can use natsort with Laravel.
My actual code is:
public function episodes()
{
return $this->hasMany('Episode')->orderBy('serial_no');
}
If there is no real solution, my idea is to have a second function like orderByNat with returns the data with return natsort($this);
How could I extend this, if there is no better option?
Thanks Andreas
Maybe something like this :
public function episodes()
{
return $this->hasMany('Episode')->orderBy(DB::raw('LENGTH(serial_no), serial_no'));
}
Never tried that ^^
Please or to participate in this conversation.