在我的laravel 5.6应用程序中,我具有以下指向付款视图文件中的payment.blade.php文件的路由链接,
<a class="btn btn-primary" href="{{route('payments.payment',$vehicles->id)}}" role="button">Go Premium</a>
此页面的路线是
Route::get('myads/{id}/edit/payment', function(){
return view('payments.payment');
})->name('payments.payment');
在payment.blade.file文件中,我有以下表单操作
<form method="post" action="{{route('payments.payment', ['id' => $vehicles->id])}}">
{{csrf_field()}}
是执行路线,
Route::get('/add-order/{id?}', 'PController@addOrder')->name('payments.payment');
通常我需要通过上面的链接进入付款刀片文件,并使用刀片提交按钮提交表格。但是在我的应用程序中,当我单击 go premium 按钮访问付款刀片文件时,它没有重定向到付款按钮。它是执行付款刀片文件形式的操作,而没有显示付款刀片文件。我该如何解决这个问题?
请查看我编辑的路线和表单操作
Route::get('myads/{id}/edit/payment', function(){
return view('payments.payment');
})->name('payments.viewpayment');
和
Route::post('/add-order/{id?}', 'PController@addOrder')->name('payments.payment');
并采取行动
<form method="post" action="{{route('payments.viewpayment', ['id' => $vehicles->id])}}">
但现在出现此错误,
(1/1) MethodNotAllowedHttpException
该如何解决?
adOder功能
public function addOrder(Request $request,$id = null)
{
DB::table('vehicles')
->where('id', $id)
->update(['adtype' => '1']);
}
当前代码
Route::get('myads/{id}/edit/payment', function($vehicle_id){
return view('payments.payment',compact('vehicle_id'));
})->name('payments.payment');
Route::post('/add-order/{id}', 'PController@addOrder')->name('payments.payment');
链接到付款刀片
<a class="btn btn-primary" href="{{url('myads/'.$vehicles->id.'/edit/payment')}}" role="button">Go Premium</a>
表单动作
<form method="post" action="{{route('payments.payment', ['id' => $vehicle_id])}}">
和控制器
public function addOrder($id = null)
{
DB::table('vehicles')
->where('id', $id)
->update(['adtype' => '1']);
}
答案 0 :(得分:2)
您可以为同一视图的get
和post
方法使用相同的名称
在您的锚标记中
<a class="btn btn-primary" href="{{url('myads/'.$vehicles->id.'/edit/payment')}}" role="button">Go Premium</a>
在您的路线文件中
Route::get('myads/{id}/edit/payment', function($id){
return view('payments.payment',compact('id'));
})->name('payments.payment');
Route::post('/add-order/{id}', 'PController@addOrder')->name('payments.payment');
在您的表单标签中
<form method="post" action="{{route('payments.payment', ['id' => $id])}}">
您需要使用函数中的成功消息重定向回
public function addOrder($id = null)
{
DB::table('vehicles')
->where('id', $id)
->update(['adtype' => '1']);
return redirect()->back()->with('success', 'Successfully added');
}
答案 1 :(得分:1)
尝试使用差异object
路线
name routes
动作
Route::get('myads/{id}/edit/payment', function(){
return view('payments.payment');
})->name('payments.viewpayment');
Route::post('/add-order/{id?}', 'PController@addOrder')->name('payments.payment');