【发布时间】:2014-08-22 16:56:33
【问题描述】:
我正在尝试在我的 Laravel 4 应用中使用 Moltin Cart:
- 我通过 composer 安装了 Moltin Cart,
- 然后添加服务提供者 ('Moltin\Cart\CartServiceProvider')
- 并添加了别名 ('Cart' => 'Moltin\Cart\Facade')。
现在我只想登录用户访问购物车,所以我添加了
$this->beforeFilter('auth', array('only' => 'postAddToCart', 'getCart', 'getRemoveItem'));
在我的 storeController 中。
但是当我尝试访问时出现此错误
Declaration of Moltin\Cart\Storage\LaravelSession::insertUpdate() must be compatible with Moltin\Cart\StorageInterface::insertUpdate(Moltin\Cart\Item\Line $item)
我的商店控制器是:
<?php
class StoresController extends \BaseController {
public function __construct()
{
parent::__construct();
$this->beforeFilter('csrf', array('on' => 'post'));
$this->beforeFilter('auth', array('only' => 'postAddToCart', 'getCart', 'getRemoveItem'));
}
public function getIndex()
{
return View::make('stores.index')
->with('products', Product::take(4)->orderBy('created_at', 'DESC')->get());
}
public function getView($id)
{
return View::make('stores.view')
->with('product', Product::find($id));
}
public function getCategory($category_id)
{
return View::make('stores.category')
->with('products', Product::where('category_id', '=', $category_id)->paginate(6))
->with('category', Category::find($category_id));
}
public function getSearch()
{
$keyword = Input::get('keyword');
return View::make('stores.search')
->with('products', Product::where('title', 'LIKE', '%'. $keyword . '%')->get())
->with('keyword', $keyword);
}
public function postAddToCart()
{
$product = Product::find(Input::get('id'));
$qunatity = Input::get('qunatity');
Cart::insert(array(
'id' => $product->id,
'name' => $product->name,
'price' => $product->price,
'qunatity' => $qunatity,
'image' => $product->image
));
return Redirect::to('store/cart');
}
public function getCart()
{
return View::make('stores.cart')->with('products', Cart::contents());
}
public function getRemoveItem($identifier)
{
$product = Cart::item($identifier);
$product->remove();
return Redirect::to('store/cart');
}
}
【问题讨论】: