2

I have a named route

Route::get('login/facebook', array(
      'as'   > 'login.facebook.authorise', 
      'uses' => 'AuthController@getFBAuthorise'
));

and want to produce a URL pointing to it with a query string appended.

For example:

URL::route('login.facebook.authorise', array("next"=>'/dashboard/')

would produce

/login/facebook?next=/dashboard/

Is something like this built in to the framework? If not, what is the best way to try and do this?

Thanks.

3 Answers 3

1

The URL helper can do this.

http://laravel.com/docs/helpers#urls

echo link_to_route('route.name', $title, $parameters = array(), $attributes = array());

EDIT: To get only the URL :

http://laravel.com/docs/routing#named-routes

$url = URL::route('route.name', $parameters);

Sign up to request clarification or add additional context in comments.

3 Comments

That generates an HTML link with tags - not a raw URL
Sorry. URL::route() will do what you want.
Neither link_to_route() nor URL::route() will create a URL with a query string added to it. Laravel route and URL functions just aren't made to work with query strings. For that, just use PHP's http_build_query().
1

I am a bit late to the party

Just dove into the classes and methods for building urls and you can do this:

link_to_route('login.facebook.authorise','Facebook Login',array('next'=>'/Dashboard/'))

So. the array will always fallback to query params unless the names are declared in the route.

Comments

0

If the use case for this is redirecting to a page after logging in then you could use

Redirect::intended('dashboard');

As seen here http://laravel.com/docs/security#authenticating-users

Sorry if that's not what you're trying to achieve.

1 Comment

I knew about the intended routing but this is to be used across other parts of the site also. I also want a quick way to generate urls with tracking information. In emails I send out, I want to build complex query strings. Is there a built in way to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.