Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass parameters to a redirect route in Request

Tags:

Language is a model binding in route file.

Route

Route::post('managment/{Language}/create', ['as' => 'dictionary.store', 'uses' => 'DictionaryController@store' ]);

I like to declare a Request (DictionaryRequest) file which extends Request(FormRequest), and it's responsible for the request parameter at Controller.

method prototype is :

public function store(DictionaryRequest $request, Language $lang)

the redirectRoute in the request class is set as :

protected $redirectRoute = "dictionary.create";

how can I pass on parameter to the route?? (the Langauge model)

I checked FormRequest class, but redirectRoute just passes on to the UrlGenerator with no parameters.

/**
 * Get the URL to redirect to on a validation error.
 *
 * @return string
 */
protected function getRedirectUrl()
{
    $url = $this->redirector->getUrlGenerator();

    if ($this->redirect) {
        return $url->to($this->redirect);
    } elseif ($this->redirectRoute) {
        return $url->route($this->redirectRoute);
    } elseif ($this->redirectAction) {
        return $url->action($this->redirectAction);
    }

    return $url->previous();
}
like image 312
Nima Avatar asked Jun 01 '16 12:06

Nima


People also ask

Which of the following is a correct syntax for redirecting to a named route?

return redirect()->route('home');

What is Route parameter in laravel?

Laravel routes are located in the app/Http/routes. php file. A route usually has the URL path, and a handler function callback, which is usually a function written in a certain controller.

How do I redirect one page to another in laravel?

Redirect to a specific page in Laravel using ajax - Stack In order to redirect everything on web routes, you can add the following piece of code in your app's route/web. php file Route::any( '{catchall}', function(){ // return redirect( 'https://digitizor.com' ) // OR, Do something here })->where( 'catchall', '.


1 Answers

Did you try override getRedirectUrl?

/**
 * Get the URL to redirect to on a validation error.
 *
 * @return string
 */
protected function getRedirectUrl()
{
    $url = $this->redirector->getUrlGenerator();

    return $url->route($this->redirectRoute, [ /*your parameters*/ ]);

}
like image 68
huuuk Avatar answered Sep 28 '22 15:09

huuuk