[英]Redirect to route not working in Laravel 5
我有一个应用程序,用户提交一个表单,执行SOAP交换以从Web API获取一些数据。 如果在特定时间内请求太多,则Throttle服务器拒绝访问。 我为这个名为throttle.blade.php
创建了一个自定义错误视图,该视图保存在resources\\views\\pages
。 在routes.php
我将路由命名为:
Route::get('throttle', 'PagesController@throttleError');
在PagesController.php
我添加了相关的函数:
public function throttleError() {
return view('pages.throttle');
}
这是我为执行SOAP交换而创建的SoapWrapper
类:
<?php namespace App\Models;
use SoapClient;
use Illuminate\Http\RedirectResponse;
use Redirect;
class SoapWrapper {
public function soapExchange() {
try {
// set WSDL for authentication
$auth_url = "http://search.webofknowledge.com/esti/wokmws/ws/WOKMWSAuthenticate?wsdl";
// set WSDL for search
$search_url = "http://search.webofknowledge.com/esti/wokmws/ws/WokSearch?wsdl";
// create SOAP Client for authentication
$auth_client = @new SoapClient($auth_url);
// create SOAP Client for search
$search_client = @new SoapClient($search_url);
// run 'authenticate' method and store as variable
$auth_response = $auth_client->authenticate();
// add SID (SessionID) returned from authenticate() to cookie of search client
$search_client->__setCookie('SID', $auth_response->return);
} catch (\SoapFault $e) {
// if it fails due to throttle error, route to relevant view
return Redirect::route('throttle');
}
}
}
一切正常,直到我达到Throttle服务器允许的最大请求数,此时它应显示我的自定义视图,但它显示错误:
InvalidArgumentException in UrlGenerator.php line 273:
Route [throttle] not defined.
我无法弄清楚为什么说没有定义路线。
您没有为路线定义名称,只定义路径。 您可以像这样定义您的路线:
Route::get('throttle', ['as' => 'throttle', 'uses' => 'PagesController@throttleError']);
该方法的第一部分是您在案例中定义路径的路径,如/throttle
。 作为第二个参数,您可以使用选项传递数组,您可以在其中指定路径( as
)和回调(在本例中为控制器)的唯一名称。
您可以在文档中阅读有关路线的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.