📅  最后修改于: 2022-03-11 14:54:21.105000             🧑  作者: Mango
} public function store($product_id,$product_name,$product_price) { Cart::add($product_id,$product_name,1,$product_price)->associate('App\Models\Product'); session()->flash('success_message','Item added in cart'); return redirect()->route('product.cart'); } use WithPagination; public function render() { if($this->sorting=='date') { $products = Product::orderBy('created_at','DESC')->paginate($this->pagesize); }else if($this->sorting=="price"){ $products = Product::orderBy('regular_price','ASC')->paginate($this->pagesize); }else if ($this->sorting=="price-desc") { $products = Product::orderBy('regular_price','DESC')->paginate($this->pagesize); }else { $products = Product::paginate($this->pagesize); } $categories = Category::all(); return view('livewire.shop-component', ['products'=> $products])->layout("layouts.base"); }}