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