Search
 
SCRIPT & CODE EXAMPLE
 

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();
Comment

PREVIOUS NEXT
Code Example
Php :: php require 
Php :: mysqli exception handling 
Php :: laravel factory relations data 
Php :: laravel route required parameters 
Php :: return only one column data from table in codeigniter 
Php :: woocommerce product hooks 
Php :: php if elseif endif 
Php :: php foreach loop first element 
Php :: php stop loading page 
Php :: Notice: Array to string conversion php 
Php :: how to insert data in table and fetch in wordpress 
Php :: job with queue name 
Php :: error 500 internal server error in laravel 
Php :: laravel create on model 
Php :: laravel create session table 
Php :: calculate array length in php 
Php :: convert png to webp in php 
Php :: laravel model set new attribute 
Php :: Laravel jwt check token sent by request is valid 
Php :: Arr::only laravel 
Php :: bagisto package generator 
Php :: laravel model column default value 
Php :: php get variable by string name 
Php :: PHP Fatal error: Allowed memory size of 1610612736 bytes exhausted 
Php :: array join pgp 
Php :: php meta 
Php :: create symfony demo app 
Php :: php date 
Php :: spaceship operator php 
Php :: laravel request input default value 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =