Php 当方法更改为“获取路线”时,与POST方法Laravel不一样
我看到了一个搜索栏:Php 当方法更改为“获取路线”时,与POST方法Laravel不一样,php,laravel,laravel-routing,laravel-request,Php,Laravel,Laravel Routing,Laravel Request,我看到了一个搜索栏: {!! Form::open(['name' => 'myForm', 'method' => 'GET', 'action' => 'AreaController@search', 'files' => true, 'onsubmit' => "return validateForm()"]
{!! Form::open(['name' => 'myForm',
'method' => 'GET',
'action' => 'AreaController@search',
'files' => true,
'onsubmit' => "return validateForm()"])
!!}
{!! Form::submit('جستجو', ['class' => 'btn btn-info']) !!}
{!! Form::close() !!}
在路由文件中,web.php
:
Route::get('area/search/', 'AreaController@search')->name('area.search');
区域控制器
:
public function search(Request $request) {
return " it is working" ;
}
但当我点击按钮时,浏览器显示一个空白页面。当我使用POST
方法时,它正在工作,但如果我更改为GET
方法,它就不工作了
谢谢。对于Post方法,您需要将CSRF令牌添加到表单中
{!! Form::open(['method' => 'POST']) !!} <--------- Change to POST method
{!! Form::token() !!} <----------- Add this line
{!! Form::submit('جستجو', ['class' => 'btn btn-info']) !!}
{!! Form::close() !!}
Route::post('area/search/', 'areacontroller@search')->name('area.search');
有关更多详细信息,您可以参考我想这是一个LaravelCollective表单?使用
'action'=>时,根本不确定您的路线是否被击中AreaController@search“
。此外,您的帖子设置为接受文件上传'files'=>true
。。。因此,您的方法必须是posi-removed'files'=>true,而不是'action'=>'AreaController@search'使用了'route'=>['area.search'],但当我将路由从area/search/更改为area search时,仍然不工作。成功了!!!
Route::post('profile', array('before' => 'csrf', function()
{
//
}));