class UserController extends Controller{
public function index()
{
$columns = ['id', 'name', 'email', 'created_at'];
$users = User::addSelect([
'last_post_title' => Post::select(['title'])
->whereColumn('user_id', 'users.id')
->where('status', Post::STATUS_NORMAL)
->orderByDesc('created_at')
->limit(1)
])->orderByDesc('id')->paginate(20, $columns);
return view('user.index', ['users' => $users]);
}}
登入後複製