Answers for "laravel how to join 2 tables"

PHP
11

join 2 tables laravel

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();
Posted by: Guest on December-09-2020
3

join multiple tables in laravel eloquent

$users = User::join('posts', 'posts.user_id', '=', 'users.id')
            ->where('users.status', 'active')
            ->where('posts.status','active')
            ->get(['users.*', 'posts.descrption']);
Posted by: Guest on September-16-2021
1

laravel join 2 tables eloquent

$select->joinSub(
                    $selectSubQry,
                    'ag',
                    'ag.id',
                    '=',
                    'agp.userId'
                );
Posted by: Guest on June-15-2020
0

how to join two tables in laravel

use Illuminate\Support\Facades\DB;
//in the following example we will join two tables
//a products table and categories table
$categoryProducts = Product::join('categories', 'categories.id', '=', 'products.category_id')
        ->select('products.*', 'categories.category_name')
        ->where('products.status', 1)
        ->get();
Posted by: Guest on May-22-2022

Code answers related to "laravel how to join 2 tables"

Browse Popular Code Answers by Language