$users = User::with(['student' => function ($q) {
$q->orderBy('id', 'desc');
}]);
public function latestPost()
{
return $this->hasOne(AppPost::class)->latest();
}
$users = Topic::with('latestPost')->get()->sortByDesc('latestPost.created_at');
<?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
}
}
$order = 'desc';
$users = User::join('roles', 'users.role_id', '=', 'roles.id')->orderBy('roles.label', $order)->select('users.*')->paginate(10);
$counties = County::whereHas('items', function ($query) {
$query->where('approved', 1);
})->orderBy('name')->get();