Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel orderby with relation

$users = User::with(['student' => function ($q) {
            $q->orderBy('id', 'desc');
        }]);
Comment

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') ;
}
Comment

PREVIOUS NEXT
Code Example
Php :: php recursive function to build array 
Php :: taxonomy_get_children drupal 8 
Php :: how to insert date in mysql using php 
Php :: laravel throw function 
Php :: infinite cookie good php ? 
Php :: php select option selected from database 
Php :: convert text file to json php 
Php :: php createFromFormat day of week 
Php :: remove first 4 characters in string php 
Php :: php curl Content-Length 
Php :: multiple logical condition in laravel query 
Php :: laravel check if request has value 
Php :: wordpress php query randomise 
Php :: laravel set config 
Php :: arrow function in php 
Php :: laravel artisan call with confirm 
Php :: create laravel project with preferred version : 8 
Php :: create migration with model laravel 8 
Php :: autogenerate slug for model laravel 
Php :: custom laravel auth 
Php :: php array check 
Php :: check method in laravel 
Php :: Target class [BannerController] does not exist. 
Php :: Increase the PHP memory limit 
Php :: laravel web php request to redirect to another page 
Php :: laravel enum validation 
Php :: php extend parent constructor 
Php :: http_response_code 
Php :: and php 
Php :: New Laravel Devcontainer Project Setup 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =