gpt4 book ai didi

php - 明确定义 Laravel 路由未定义错误

转载 作者:行者123 更新时间:2023-12-05 08:13:55 25 4
gpt4 key购买 nike

我正在尝试使用 laravel 处理基本表单,但遇到了一个问题,即未检测到我的 POST 路由,并导致 blade 模板中出现路由未定义错误。我的目标是解决此错误并将表单发布到 Controller ,然后使用 $request 参数访问各种表单字段。

这是错误:Route [become-a-customer] not defined.

我很感激任何关于如何解决这个问题的建议。

表单

<form action="{{ route('become-a-customer') }}" method="post" class="col-md-8 offset-md-2">
<div class="form-row">
<div class="form-group col-md-6">
<label for="first_name">First Name</label>
<input name="last_name" type="email" class="form-control" id="first_name" placeholder="First Name">
</div>
...
</div>
<input type="hidden" name="_token " value="{{ Session::token() }}"/>
<button type="submit" class="btn">SUBMIT</button>
</form>

web.php

Route::post('/become-a-customer', 'BecomeACustomerFormController@postBecomeACustomer');

成为客户 Controller 。 php

class BecomeACustomerFormController extends Controller
{
public function postBecomeACustomer(Request $request)
{
$firstName = $request['first_name'];
$lastName = $request['last_name'];
...
...
return redirect()->back();
}
}

最佳答案

Route::post('/become-a-customer', 'BecomeACustomerFormController@postBecomeACustomer')->name('become-a-customer');

关于php - 明确定义 Laravel 路由未定义错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60593090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com