Union in laravel

use Illuminate\Support\Facades\DB; $first = DB::table('users') ->whereNull('first_name'); $users = DB::table('users') ->whereNull('last_name') ->union($first) ->get();

0 Comments

Subquery join laravel

$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(JoinClause$join) { $join->on('users.id', '=', 'latest_posts.user_id'); })->get();

0 Comments

Left & right join in laravel

$users = DB::table('users') ->leftJoin('posts', 'users.id', '=', 'posts.user_id') ->get(); $users = DB::table('users') ->rightJoin('posts', 'users.id', '=', 'posts.user_id') ->get();

0 Comments

Inner join

use Illuminate\Support\Facades\DB; $users = DB::table('users') ->join('contacts', 'users.id', '=', 'contacts.user_id') ->join('orders', 'users.id', '=', 'orders.user_id') ->select('users.*', 'contacts.phone', 'orders.price') ->get();

0 Comments

Update in laravel

A. view.blade.php <h3>Edit Bags</h3><br/> <?php $data = DB::table('bags')->where('id', $id)->get(); foreach($data as $d){ $title = $d->title; $address = $d->address; } ?> <div class="container"> <div class="card" style="padding:10px; background:white"> @if (session('message')) <div class="alert…

0 Comments