Php 在Laravel中找不到页面,路由问题
我有一个问题,我的拉威尔和可能的路线,但我不确定 所以,在模态窗口中有一个接触形式。当我点击Php 在Laravel中找不到页面,路由问题,php,laravel,laravel-5,Php,Laravel,Laravel 5,我有一个问题,我的拉威尔和可能的路线,但我不确定 所以,在模态窗口中有一个接触形式。当我点击Send按钮时,我发现页面未找到错误 我在web.php中看到的是 Route::post('/apply_now','HomeController@apply_now')->name('apply_now'); 在HomeController.php中 public function apply_now(Request $request) { ... form fields data
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>
&时代;
立即申请
*国家
提交
运行此命令,然后重试
php artisan optimize:clear
或
从中删除所有文件
/bootstrap/cache
/storage/framework/cache/data
/storage/framework/sessions
/storage/framework/views
并确保在web.php文件中定义了两个URL,如下所示:
Route::post('/','HomeController@index');
Route::post('apply_now','HomeController@apply_now')->name('apply_now');
Route::match(['get', 'post'],'/apply_now', 'HomeController@apply_now');
并确保您的服务器已打开mod rewrite。因此,Laravel可以处理.htaccess规则。创建如下路由:
Route::post('/','HomeController@index');
Route::post('apply_now','HomeController@apply_now')->name('apply_now');
Route::match(['get', 'post'],'/apply_now', 'HomeController@apply_now');
看起来代码中没有错误,你能清除缓存吗
php artisan route:cache
你看到图片中的区域了吗?试试这个
Route::get('/', 'HomeController@index')->name('home');
在控制器中
return redirect()->route('home')->with('message', 'Sent');
希望这有帮助:)尝试添加
{{ csrf_field() }}
这将向您的表单中添加CRSF令牌字段
例如,
这是laravel所要求的,默认情况下在所有路由上启用CSRF以检查post请求是否安全,您还可以从位于
app\Http\Middleware
为您的路线禁用CRSF
更新
如果希望应用程序安全,禁用此选项不是一个好做法
加
以你的形式参加
{{ Form::open(array('route'=>'apply_now','files' => true,'method'=>'post')) }}
...
form field
{{ csrf_field() }}
{{ Form::close() }}
现在,一旦您提交表单,laravel将检查crsf令牌是否与表单一起发送,并让您的请求进一步进行共享来自php artisan route:list的输出
?@NikleshRaut我已使用“立即应用”部分对其进行了更新。它有很多行,这就是为什么我只放了一个有问题的->name('apply_now')
删除这个,然后再试一次<代码>php artisan路由:清除和php artisan配置:缓存
当我删除它时,我没有定义路由[apply_now]代码>只是一种预感。尝试在中间使用index.php。我无法在共享主机上运行此操作。。或者我可以?那么您可以尝试删除/bootstrap/cache目录中的所有文件,并检查是否已删除它们。重新加载,但仍然相同。在缓存目录中,新文件现在尝试了所有提到的内容,但没有找到相同的-apply\u。得到了未定义的路由[apply\u now]。
仍然是相同的错误。即使在删除bootstrap/cacheSame“Route[apply\u now]中的文件之后未定义。
也尝试一些补偿。为什么我们要更改,以及上面代码中的错误:)基本上这是一个安全令牌,由laravel检查每个post请求,将其添加到表单中会让laravel知道提交的表单有令牌。我知道。我是说你应该解释你的答案哦,这很容易理解。你也可以使用这样的令牌@csrf@RajdeepTayde,即使没有I add{{csrf_field()},也已经有了安全令牌您是否在LocalHost上运行它?是的,确实,我已经修复了它,但是仍然找不到输出。请尝试此命令。php artisan优化php artisan缓存:清除php artisan路由:缓存php artisan查看:清除php artisan配置:缓存