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 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 :: laravel if syntax 
Php :: php http_build_query 
Php :: woocommerce order get_data() 
Php :: convert float to integer laravel 
Php :: php print array new line 
Php :: check type in php 
Php :: how to find this day is holiday in php day 
Php :: php round() function 
Php :: laravel get subdomain 
Php :: php get ip from host 
Php :: format money with commas in php 
Php :: php get class name without namespace from string 
Php :: php explode multiple delimiters 
Php :: array_last in laravel 8 
Php :: install soap in php linux 
Php :: if object or array in php 
Php :: wordpress set image quality 
Php :: laravel form in 24 hours format 
Php :: foreach loop 1-100 php 
Php :: create form request laravel 
Php :: php convert month number to name 
Php :: blade condition if else laravel 
Php :: array reduce associative array php 
Php :: Laravel randomise data from database 
Php :: carbon diff 
Php :: php remove everything after symbol 
Php :: laravel subtract date 
Php :: php last day of month 
Php :: laravel log could not be opened fix 
Php :: laravel create text file 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =