laravel select all code example
Example 1: laravel wher in
$users = DB::table('users')
->whereIn('id', [1, 2, 3])
->get();
Example 2: laravel join
$latestPosts = DB::table('posts')
->select('user_id', DB::raw('MAX(created_at) as last_post_created_at'))
->where('is_published', true)
->groupBy('user_id');
$users = DB::table('users')
->joinSub($latestPosts, 'latest_posts', function ($join) {
$join->on('users.id', '=', 'latest_posts.user_id');
})->get();
Example 3: DB::table('users')->get();
$users = DB::table('users')->get();
Example 4: DB::table('users')->get();
DB::select('SELECT * FROM users WHERE name = "'.Input::get('name').'"');
Example 5: laravel having
$users = DB::table('users')
->groupBy('account_id')
->having('account_id', '>', 100)
->get();