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

PREVIOUS NEXT
Code Example
Php :: getting input value in session variable in php 
Php :: php usort method of class 
Php :: join table laravel count 
Php :: php time() function 
Php :: how to run multiple seeder at a time in laravel 
Php :: redirect 404 in laravel 
Php :: laravel price database 
Php :: php get url after question mark 
Php :: if condition in smarty 
Php :: yii2 dataprovider to model 
Php :: laravel eloquent soft delete 
Php :: laravel hasmany 
Php :: laravel new line in language file 
Php :: get first word from string php 
Php :: how to remove keys in subarray php 
Php :: how to make zip in php by multiple files 
Php :: array to string using php method 
Php :: php mongodb dll 
Php :: name of today php 
Php :: add text next to price woocommerce 
Php :: laravel create mode 
Php :: php artisan create controller inside folder 
Php :: mysqli_connect php 
Php :: php tomorrow 
Php :: img src php wordpress theme child 
Php :: php line break 
Php :: get file extension php 
Php :: centos 8 laravel permission denied 
Php :: laravel attach once 
Php :: laravel amount migration 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =