我正在尝试在Laravel中实现仅包含会话变量的购物车系统。
但是当我提交表格时:
<form method="POST" action="{{ route('panierAdd') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<table>
<tr>
<td>
Nombre de serveurs physiques
</td>
<td>
<select id="nb_serveurs" name="nb_serveurs"><option value="0">Choisir une option</option><option value="1" selected="selected" >1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select>
</td>
</tr>
<tr>
<td>
Type de licence
</td>
<td>
<select id="type" name="type"><option value="0">Choisir une option</option><option value="1" selected="selected" >Illimitée</option><option value="2">Standard</option></select>
</td>
</tr>
<tr>
<td>
Durée
</td>
<td>
<select id="duree" name="duree"><option value="0">Choisir une option</option><option value="1" selected="selected">1 an</option><option value="2">2 ans</option><option value="3">3 ans</option></select>
<a class="reset_variations" href="#">Effacer</a>
</td>
</tr>
</table>
<div style="width:100%;height:50px;" id="div-price">
<div class="price"><span id="total">495,00 € HT</span></div>
</div>
<div class="panier-button">
<input type="submit" class="single_add_to_cart_button button alt joli-boutton" id="panier-go" value="Ajouter au panier"/>
</div>
</form>
有我的路线:
Route::post('/panier/add',[
"uses" => "ProductController@addToCard",
"as" => "panierAdd"
]);
Route::delete('panier/delete',[
"uses" => "ProductController@deleteFromCard",
"as" => "panierDelete"
]);
Route::get('panier',[
"uses" => "ProductController@card",
"as" => "panier"
]);
这是ProductController:
class ProductController extends Controller
{
public function addToCard (Request $request){
$nb_serveurs = $request->nb_serveurs;
$type = $request->type;
$duree = $request->duree;
$product = new Produit($nb_serveurs, $type, $duree);
if (Session::has('panier'))
{
$panier = Session::get('panier');
$id = Session::get("id")+1;
}else{
$panier = new Panier();
$id = 1;
}
$panier->addItem($product, $id);
$panier->calcPrixTot();
Session::put("panier", $panier);
Session::put("id", $id);
return Redirect::route('panier');
}
public function deleteFromCard (Request $request){
Session::forget('panier');
if(Session::has('panier')){
return view("panier.panier");
}else{
return view('index');
}
}
public function card (Request $request){
return view('panier.panier');
}
}
当我提交表格时,以下是它给我的信息:
MethodNotAllowedHttpException in RouteCollection.php line 218
我做错了什么?
答案 0 :(得分:0)
这将与您的路由有关。我会尝试两件事,从路径uri中删除第一个斜杠并交换as并使用键。试试这个
Route::get('panier/add', ['as' => 'panierAdd', "uses" => "ProductController@addToCard"]);