【发布时间】:2020-08-08 00:00:30
【问题描述】:
如何在 laravel 中发送带有GET 路由的表单POST 方法?
路线
Route::get('domain_detail/{domain_name}','domain_detailController@index');
查看 domain_detail 文件夹
<form method="post" action="{{url('domain_detail')}}/{{strtolower($domain_detail->domain_name)}}">
<div class="form-group">
<label for="namefamily">namefamily</label>
<input type="text" class="form-control round shadow-sm bg-white text-dark" name="namefamily">
</div>
<div class="form-group">
<label for="mobile">mobile</label>
<input type="text" class="form-control round shadow-sm bg-white text-dark" name="mobile">
</div>
<div class="form-group">
<label for="myprice">myprice</label>
<input type="number" class="form-control round shadow-sm bg-white text-dark" name="myprice">
</div>
<div class="form-group">
<input type="submit" name="send_price" class="btn btn-success" value="submit">
</div>
</form>
控制器
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class domain_detailController extends Controller
{
public function index($domain_name)
{
$domain_detail_exist = DB::table("domains")->where('domain_name', $domain_name)->exists();
if ($domain_detail_exist) {
$domain_detail = DB::table("domains")->where('domain_name', $domain_name)->first();
return view('domain_detail/index', ['domain_detail' => $domain_detail]);
} else {
return view('404');
}
}
public function create()
{
return view('domain_detail.index');
}
}
在控制器上,我没有在create 函数中添加任何代码,但是当我单击表单中的提交按钮时,我得到了这个错误
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持 POST 方法。支持的方法: 得到,头。
【问题讨论】:
-
尝试将表单的方法设置为获取而不是发布:
-
@Yasin Karimian,我的遮阳篷解决了您的问题吗?如果是这样,请将其标记为正确,以便可能遇到相同问题的其他人可以查阅此帖子以找到可能的解决方案