[英]Page not found in Laravel, routes problem
我的Laravel和可能的路线有问题,但我不确定。
因此,模态窗口中有一个联系表单。 当我点击Send
按钮时,我找不到页面错误。
我在web.php
有什么
Route::post('/apply_now','HomeController@apply_now')->name('apply_now');
在HomeController.php
public function apply_now(Request $request)
{
... form fields data
return Redirect::to('/')->with('message', 'Sent');
}
形式
{{Form::open(array('route'=>'apply_now','files' => true,'method'=>'post'))}}
...
form field
{{Form::close()}
错误
未找到
在此服务器上找不到请求的URL / apply_now。
我没有看到路线有什么问题,但却找不到问题。
更新:
| | POST | apply_now | apply_now | App\Http\Controllers\HomeController@apply_now
更新2.模态
<!-- Apply Modal -->
<div class="modal fade" id="apply" tabindex="-1" role="dialog" aria-labelledby="applyModalLable">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title text-center" id="applyModalLable">Apply Now</h4>
</div>
<div class="modal-body">
<form method="POST" action="https://example.com/apply_now" accept-charset="UTF-8" enctype="multipart/form-data">
<input name="_token" type="hidden" value="OyEdnHIWRgbZmPo0joodNmWraDSuuACIrwqup044">
<div class="form-group ">
<input type="text" name="your_name" class="form-control" placeholder="*Your Name" value="" >
</div>
<div class="form-group ">
<label>*Country</label>
<input type="text" name="country" class="form-control" placeholder="Your Country" >
</div>
<div class="form-group ">
<input type="text" name="contact_email" class="form-control" placeholder="*Contact Email" >
</div>
<div class="form-group ">
<input type="text" name="contact_phone" class="form-control" placeholder="*Contact Phone">
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-custom btn-sm btn-block">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
制作这样的路线:
Route::match(['get', 'post'],'/apply_now', 'HomeController@apply_now');
尝试添加
{{ csrf_field() }}
这会将CRSF令牌字段添加到表单中
例如。 <input type="hidden" name="_token" value="SomeRandomString">
如果laravel需要,CSRF默认在所有路由上启用,以检查发布请求是否安全,您也可以从VerifyCsrfToken.php中禁用它,该中间件位于
app\Http\Middleware
为路由更新禁用CRSF
protected $except = [
//
'apply_now'
];
如果您希望应用程序安全,禁用此功能不是一个好习惯
加
{{ csrf_field() }}
在你的形式.eg。
{{ Form::open(array('route'=>'apply_now','files' => true,'method'=>'post')) }}
...
form field
{{ csrf_field() }}
{{ Form::close() }}
现在,一旦您提交表单,laravel将检查是否与表单一起发送了crsf令牌,并让您的请求继续进行
运行此命令,然后重试
php artisan optimize:clear
要么
从中删除所有文件
/bootstrap/cache
/storage/framework/cache/data
/storage/framework/sessions
/storage/framework/views
并确保您已将两个URL定义到web.php文件中,如下所示:
Route::post('/','HomeController@index');
Route::post('apply_now','HomeController@apply_now')->name('apply_now');
并确保您的服务器已打开mod重写。 所以Laravel可以处理.htaccess规则。
试试这个,
Route::get('/', 'HomeController@index')->name('home');
在你的控制器中
return redirect()->route('home')->with('message', 'Sent');
希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.