eski009
eski009

Reputation: 371

Generating query strings in Laravel 4

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.

Upvotes: 2

Views: 5144

Answers (3)

mattems
mattems

Reputation: 78

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.

Upvotes: 1

Alexandre Danault
Alexandre Danault

Reputation: 8682

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);

Upvotes: 1

tymondesigns
tymondesigns

Reputation: 451

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.

Upvotes: 0

Related Questions