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 :: Debloat Wordpress 
Php :: Argument #1 ($baseObject) must be of type DateTimeInterface, string given 
Php :: array_map with user functions php and parameter php 
Php :: laravel migration example 
Php :: Change COD default order status to “On Hold” instead of “Processing” in Woocommerce 
Php :: laravel seeder with relationship 
Php :: php ussd 
Php :: Custom searchform 
Php :: WordPress Creating “startupl” folder and Wrtting to .htaccess 
Php :: run multiple php scripts parallel 
Php :: php send POST request same folder 
Php :: como leer archivos .env php 
Php :: laravel collection modelKeys 
Php :: AAPL_041621C125@3.25SL2.00 
Php :: Insert Data using modal 
Php :: add code in header 
Php :: Best Performance monitoring tools for php 
Php :: wp plugin handles deregister 
Php :: refresh database tables yii 1 
Php :: where clause with paginate laravel multiple column 
Php :: yajra add column 
Php :: nodejs php 
Php :: read an email with php 
Php :: php stristr 
Php :: how use variable in string in laravel 
Php :: what Permissions do I need for include folder on php 
Php :: laravel carbon y-m-d 
Java :: java get screen size 
Java :: android glide dependency 
Java :: isprime check formula java 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =