app/Http/Controllers/ProductController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index()
    {
        if (Auth::user()->hasRole('administrator')) {
            $products = Product::all();
            return view('admin.product_admin.index', compact('products'));
        } elseif (Auth::user()->hasRole('user')) {
            $products = DB::table('user_products')
                        ->join('products', 'user_products.product_id', '=', 'products.product_id')
                        ->join('users', 'user_products.user_id', '=', 'users.id')
                        ->select('products.product_id', 'products.name', 'products.image_path', 'users.username', 'products.description', 'users.image', 'users.id')
                        ->where('products.status', '=', 1)
                        ->where('products.category', '=', 'equipment')
                        ->orderBy('products.created_at', 'DESC')
                        ->get();
            return view('products.index', compact('products'));
        }
    }
public function index ( ) { if ( Auth :: user ( ) -> hasRole ( 'administrator' ) ) { $ products = Product :: all ( ) ; return view ( 'admin.product_admin.index' , compact ( 'products' ) ) ; } elseif ( Auth :: user ( ) -> hasRole ( 'user' ) ) { $ products = DB :: table ( 'user_products' ) -> join ( 'products' , 'user_products.product_id' , '=' , 'products.product_id' ) -> join ( 'users' , 'user_products.user_id' , '=' , 'users.id' ) -> select ( 'products.product_id' , 'products.name' , 'products.image_path' , 'users.username' , 'products.description' , 'users.image' , 'users.id' ) -> where ( 'products.status' , '=' , 1 ) -> where ( 'products.category' , '=' , 'equipment' ) -> orderBy ( 'products.created_at' , 'DESC' ) -> get ( ) ; return view ( 'products.index' , compact ( 'products' ) ) ; } }
Display a listing of the resource.
Display a listing of the resource .
// $products = Product::all(); // $products = DB::table('products') //                 ->where('status', '=', 1) //                 ->get(); // $products = Product::with('user') //                 ->where('products.status', '=', 1) //                 ->where('products.category', '=', 'equipment') //                 ->get(); //dd($products);