2015-05-28 70 views
5

我有一個應用程序,用戶提交表單執行SOAP交換以從Web API獲取一些數據。如果在特定時間內請求太多,則Throttle服務器拒絕訪問。我爲這個名爲throttle.blade.php的自定義錯誤視圖保存了resources\views\pages。在routes.php我已經命名爲路線:在PagesController.php我已經加入了相關的功能重定向到路由不工作在Laravel 5

Route::get('throttle', '[email protected]'); 

public function throttleError() { 
    return view('pages.throttle'); 
} 

這裏是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'); 
    } 
} 
} 

一切正常,直到我達到Throttle服務器允許的最大請求數量,在此時它應該顯示m y自定義視圖,但它顯示錯誤:

InvalidArgumentException in UrlGenerator.php line 273: 
Route [throttle] not defined. 

我想不通它爲什麼說路由沒有定義。

回答

11

您沒有爲您的路線定義名稱,只有路徑。您可以定義您的路線是這樣的:

Route::get('throttle', ['as' => 'throttle', 'uses' => '[email protected]']); 

該方法的第一部分是在你的情況,你定義它像/throttle路由的路徑。作爲第二個參數,您可以將數組傳遞給選項,您可以在其中指定路由的唯一名稱(as)和回調(在本例中爲控制器)。

您可以在documentation瞭解更多關於路線的信息。