以下是我的路线档案,即 web.php
Route::post('finddomainname','DomainController@finddomainname')->name('finddomainname');
Route::post('registerdomains','DomainController@registerdomains')->name('registerdomains');
以下是我的 DomainController 上的代码,用于所使用的操作,
public function finddomainname(Request $request)
{
$this->validate($request,
['searchdomaintxt'=>'required',
'searchdomainext'=>'required']);
$searchdomaintxt = $request->input('searchdomaintxt');
$searchdomainext = $request->input('searchdomainext');
$domainname="";
if($searchdomaintxt && $searchdomainext)
{
foreach($searchdomainext as $ext)
{
$domainname.=$searchdomaintxt.".".$ext.",";
}
//dd($domainnames);
$domainnames= rtrim($domainname,',');
$response=$this->soap->multidomainsearch($domainnames);
$result=$response['RESPONSE']['DOMAINSEARCH'];
//dd($result);
if($result){
//return redirect()->action('searchresults', array('response' => $result));
return view('domain.searchresults',['response'=>$result]);
}
else
{
return view('domain.searchresults',['response'=>'']);
}
}
}
以下是提交数据后控制的第二个动作
public function registerdomains(registerDomainsValidation $request)
{
$domains=$request->input('selecteddomains');
$selectedyear =$request->input('selectedyear');
$domaincontactid=\Session::get('domaincontactid');
$alldomains='';
foreach($domains as $domain)
{
$alldomains.=$domain.",";
}
$alldomains=rtrim($alldomains,',');
$response=$this->soap->registerdomains($alldomains,$domaincontactid,$selectedyear);
return view('domain.searchresults',['response'=>$response]);
}
但是当我提交数据时,它会显示此错误
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
答案 0 :(得分:0)
您正尝试使用POST
请求访问GET
路由,这就是您收到MethodNotAllowedHttpException
的原因。要解决此问题,请确保您的<form></form>
标记包含相应的method
属性。
<form action="{{ YOUR_URL }}" method="POST">
...
</form>
或者,如果您要在控制器中执行 请求,可以使用Guzzle
发送http请求。在您的控制器中,您可以:
use GuzzleHttp\Client;
$client = new Client();
$response = $client->request('POST', 'YOUR_URL', [
'form_params' => [
'foo' => 'bar'
]
]);