Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel orderby with relation

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

laravel Order by relationship

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

$users = Topic::with('latestPost')->get()->sortByDesc('latestPost.created_at');
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

laravel relationship order by

<?php
public function comments()
{
    return $this->hasMany('Comment')->orderBy('column');
}
// two
class User
{
    public function comments()
    {
        return $this->hasMany('Comment');
    }
}

class Controller
{
    public function index()
    {
        $column = Input::get('orderBy', 'defaultColumn');
        $comments = User::find(1)->comments()->orderBy($column)->get();

        // use $comments in the template
    }
}
Comment

laravel query order by relation

$order = 'desc';
$users = User::join('roles', 'users.role_id', '=', 'roles.id')->orderBy('roles.label', $order)->select('users.*')->paginate(10);
Comment

laravel OrderBy on Eloquent whereHas relationship

$counties = County::whereHas('items', function ($query) {
    $query->where('approved', 1);
})->orderBy('name')->get();
Comment

PREVIOUS NEXT
Code Example
Php :: foreign key in laravel 
Php :: laravel eloquent get last 
Php :: if text contains word then in php 
Php :: install phpmyadmin linux 
Php :: php check string size 
Php :: remove first element in array php 
Php :: php print character x times 
Php :: current URL without url site laravel 
Php :: Calculate the Difference Between Two Dates Using PHP 
Php :: sql repare php 
Php :: How to fix MySql: index column size too large (Laravel migrate) 
Php :: show display error php 
Php :: php pdo select 
Php :: php artisan make:auth Command "make:auth" is not defined. 
Php :: how to use multiple where condition in codeigniter 
Php :: remove action from theme wordpress 
Php :: php include and require statements 
Php :: laravel string capitalize in view 
Php :: php empty 
Php :: carbon last day of month in timestamp 
Php :: php artisan vendor:publish 
Php :: mysqli real escape string php 
Php :: php change string to url friendly 
Php :: Allowed memory size of 1610612736 bytes exhausted laravel 
Php :: publish Laravel mail pages to customize 
Php :: laravel find by 
Php :: wordpress get the product images 
Php :: laravel blade variable isset, empty or optional 
Php :: php array json encode key and value 
Php :: how to display user id from a function on a wordpress page 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =