The following tutorial column will introduce you to the usage of Laravel subquery statements. I hope it will be helpful to friends who need it!
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]); }}
The above is the detailed content of Introducing the usage of Laravel subquery statements. For more information, please follow other related articles on the PHP Chinese website!