Redirecting a route not working in Laravel 5

I have an application in which a user submits a form that performs a SOAP exchange in order to get some data from the web API. If there are too many requests at a specific time, the Throttle server denies access. I created my own error view for this called throttle.blade.php , which is stored in resources\views\pages . In routes.php I called the route as follows:

 Route::get('throttle', ' PagesController@throttleError '); 

In PagesController.php I added the corresponding function as:

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

Here is the SoapWrapper class that I created to perform SOAP exchanges:

 <?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'); } } } 

Everything works as it should until it reaches the maximum number of requests allowed by the Throttle server, after which it should display my user view, but it displays an error:

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

I can’t understand why he says the route is undefined.

+5
source share
1 answer

You have not defined a name for your route, but only a path. You can define your route as follows:

 Route::get('throttle', ['as' => 'throttle', 'uses' => ' PagesController@throttleError ']); 

The first part of the method is the route path in your case, when you defined it as /throttle . As the second argument, you can pass an array with parameters in which you can specify a unique route name ( as ) and a callback (in this case, the controller).

More information about the routes can be found in the documentation .

+11
source

All Articles