Ad

Laravel 5.2 Named Route Usage With Variable Parameter

- 1 answer

I have a route like this:

// Open New Subscription page
Route::get('/account/subscriptions/create/{menu}', ['uses' => 'Subscriptions\[email protected]', 'as' => 'subscription.create']);

In my blade template I use the named route like this:

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{!! route('organisations.index') . "/p11-c3" !!}">

But this format does not work.

How do I pass the variable menu a value while still using the named route (rather than hard coding a url in the href)?

Ad

Answer

You can pass your route parameters as the second argument to route() helper:

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="{!! route('organisations.index', ['menu' => 'p11-c3']) !!}">

Make sure you're using correct names. Your routing defines subscription.create route while your template refers to organisations.index route.

Ad
source: stackoverflow.com
Ad