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 :: The `php` command cannot be found. Please verify that PHP is installed, or set the `php.executables` setting. 
Php :: php call class method dynamically 
Php :: where with and and or in a laravel 
Php :: add json extenstion php 
Php :: php fpm test 
Php :: laravel route param blade 
Php :: laravel pagination layout issue 
Php :: accessing json data in php 
Php :: Laravel How do I get distinct values from the table along with the count of how many rows there are containing that value 
Php :: laravel restrict route methods 
Php :: convert Persian/Arabic numbers to English numbers PHP 
Php :: how to download image from url from a particular div in php 
Php :: laravel read csv file 
Php :: specification migration laravel 
Php :: laravel passport vue 401 Unauthorized 
Php :: array_walk in php 
Php :: date hour php 
Php :: php check if parameter exists in url 
Php :: recursive binary search php 
Php :: php check if link exists 
Php :: config clear without artisan 
Php :: php unique assoc array by value 
Php :: codeigniter base_url 
Php :: trait php 
Php :: german locale php 
Php :: laravel force login by id 
Php :: get value mentthod get laravel 
Php :: Uncaught ReferenceError: commonL10n is not defined 
Php :: laravel number input positive only 
Php :: Session/Session.php error codeigniter 3 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =