Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

get data from another table laravel

$id = false;
    if(auth()->user()->level != 1){
        $id = auth()->user()->id;
    }
    $data = DB::table('product')
                ->select('product.*', 'category.name AS category_name', 'users.name AS user_name')
                ->join('category', 'category.id', '=', 'product.category_id')
                ->join('users', 'users.id', '=', 'category.user_id')
                ->when($id, function($query, $id){
                    return $query->where('users.id', $id);
                })
                ->get();
Source by tutorialmeta.com #
 
PREVIOUS NEXT
Tagged: #data #table #laravel
ADD COMMENT
Topic
Name
9+6 =