重定向到路线不在Laravel 5中工作

Joh*_*son 5 php redirect soap laravel-routing laravel-5

我有一个应用程序,用户提交一个表单,执行SOAP交换以从Web API获取一些数据.如果在特定时间内请求太多,则Throttle服务器拒绝访问.我已为此调用创建了一个自定义错误视图,该视图throttle.blade.php保存在resources\views\pages.在routes.php我将路线命名为:

Route::get('throttle', 'PagesController@throttleError');
Run Code Online (Sandbox Code Playgroud)

PagesController.php我添加了相关的功能:

public function throttleError() {
    return view('pages.throttle');
}
Run Code Online (Sandbox Code Playgroud)

这是SoapWrapper我为执行SOAP交换而创建的类:

<?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');
    }
}
}
Run Code Online (Sandbox Code Playgroud)

一切正常,直到我达到Throttle服务器允许的最大请求数,此时它应显示我的自定义视图,但它显示错误:

InvalidArgumentException in UrlGenerator.php line 273:
Route [throttle] not defined.
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么说没有定义路线.

sha*_*ddy 11

您没有为路线定义名称,只定义路径.您可以像这样定义您的路线:

Route::get('throttle', ['as' => 'throttle', 'uses' => 'PagesController@throttleError']);
Run Code Online (Sandbox Code Playgroud)

该方法的第一部分是您定义它的路径/throttle.作为第二个参数,您可以使用选项传递数组,您可以在其中指定route(as)和回调(在本例中为控制器)的唯一名称.

您可以在文档中阅读有关路线的更多信息.