laravel orderBy

Posted 6 days ago by HossamAli

Hey Guys i'm trying to sort some clips according their artist name i have tried everything but nothing happens at all, I have tried this:

$clips = Clip::with('artist')->whereHas('artist', function($query){
    return $query->orderBy('name_' . $locale);
})->paginate($this->perPage);

and also tried it like this:

$clips = Clip::with(['artist' => function ($query) use ($locale){
    return $query->orderBy('name_' . $locale);
}])->paginate($this->perPage);

and i have the relation like this:

public function artist()
    {
        return $this->belongsTo('App\Models\Artist', 'artist_id', 'id');
    }

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.