Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to route not working in Laravel 5

I have an app where the user submits a form which performs a SOAP exchange to get some data from a Web API. If there are too many requests in a certain time, the Throttle server denies access. I have made a custom error view for this called throttle.blade.php which is saved under resources\views\pages. In routes.php I have named the route as:

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

In PagesController.php I have added the relevant function as:

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

Here is the SoapWrapper class I have created to perform the 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 I reach the maximum number of requests allowed by the Throttle server, at which point it should display my custom view, but it displays the error:

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

I cannot figure out why it is saying that the Route is not defined.

like image 990
John Dawson Avatar asked May 28 '15 10:05

John Dawson


1 Answers

You did not define a name for your route, only a path. You can define your route like this:

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

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

You can read more about routes in the documentation.

like image 132
Sh1d0w Avatar answered Sep 22 '22 02:09

Sh1d0w