app/Http/Controllers/HomeController.php
/**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
Show the application dashboard.
@return \Illuminate\Contracts\Support\Renderable
Show the application dashboard . @return \ Illuminate \ Contracts \ Support \ Renderable
public function index(Request $request)
    {
      $offers = Offer::where('id', '>', 0)->with('product')->orderBy('sales', 'desc')->limit(20)->get()->toArray();
        if($request->category == null){
            $products = Product::where('id', '>', 0)->paginate(9);
            $productsAr = Product::where('id', '>', 0)->paginate(9)->toArray();
        }else{
            $products = Category::where('alias', $request->category)->first()->products()->paginate(9);
            $productsAr = Category::where('alias', $request->category)->first()->products()->paginate(9)->toArray();
        }
        if($request->category == null){
            $categories = Category::where('parent', null)->get()->toArray();
            $category = null;
        }else{
            $parentAr = Category::where('alias', $request->category)->first()->toArray();
            $category = Category::where('alias', $request->category)->first()->parent()->get()->toArray();
            if(empty($category)){
            $category = null;
            }
            $categories = Category::where('parent', $parentAr['external_id'])->get()->toArray();
        }
        return view('home', ['items'=>$offers, 'categories' => $categories, 'products' =>  $products, 'productsar' => $productsAr, 'actcategory' => $category]);
    }
public function index ( Request $ request ) { $ offers = Offer :: where ( 'id' , '>' , 0 ) -> with ( 'product' ) -> orderBy ( 'sales' , 'desc' ) -> limit ( 20 ) -> get ( ) -> toArray ( ) ; if ( $ request -> category == null ) { $ products = Product :: where ( 'id' , '>' , 0 ) -> paginate ( 9 ) ; $ productsAr = Product :: where ( 'id' , '>' , 0 ) -> paginate ( 9 ) -> toArray ( ) ; } else { $ products = Category :: where ( 'alias' , $ request -> category ) -> first ( ) -> products ( ) -> paginate ( 9 ) ; $ productsAr = Category :: where ( 'alias' , $ request -> category ) -> first ( ) -> products ( ) -> paginate ( 9 ) -> toArray ( ) ; } if ( $ request -> category == null ) { $ categories = Category :: where ( 'parent' , null ) -> get ( ) -> toArray ( ) ; $ category = null ; } else { $ parentAr = Category :: where ( 'alias' , $ request -> category ) -> first ( ) -> toArray ( ) ; $ category = Category :: where ( 'alias' , $ request -> category ) -> first ( ) -> parent ( ) -> get ( ) -> toArray ( ) ; if ( empty ( $ category ) ) { $ category = null ; } $ categories = Category :: where ( 'parent' , $ parentAr [ 'external_id' ] ) -> get ( ) -> toArray ( ) ; } return view ( 'home' , [ 'items' => $ offers , 'categories' => $ categories , 'products' => $ products , 'productsar' => $ productsAr , 'actcategory' => $ category ] ) ; }
Show the application dashboard.
Show the application dashboard .