Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel Order by relationship

public function latestPost()
{
    return $this->hasOne(AppPost::class)->latest();
}

$users = Topic::with('latestPost')->get()->sortByDesc('latestPost.created_at');
Source by laracasts.com #
 
PREVIOUS NEXT
Tagged: #laravel #Order #relationship
ADD COMMENT
Topic
Name
5+6 =