Answers for "laravel sortby relationship column"

PHP
-1

laravel orderby with relation

$users = User::with(['student' => function ($q) {
            $q->orderBy('id', 'desc');
        }]);
Posted by: Guest on May-04-2020
0

laravel sortby relationship column

add the code to relationship in the method of the model
   public function room(){
      return $this->hasMany(room::class,  'id')->orderBy('id', 'DESC') ;
}
Posted by: Guest on July-22-2021

Browse Popular Code Answers by Language