Generating url relative to the base url in laravel 4 Generating url relative to the base url in laravel 4 laravel laravel

Generating url relative to the base url in laravel 4


To generate a relative URL, you can use URL::route or URL::action as they allow to pass a $absolute parameter which defaults to true. So to get a relative URL when using named routes for example, you can use the following:

URL::route('foobar', array(), false)

This will generate a URL like /foobar.


First you need to create a Named Route like

Say yo want to go to http://baseurl/user and runs the method 'showuser' define in controller 'allusers'

then your Route shold look like this:-

Route::get('user', array('as' => 'myuser', 'uses' => 'allusers@showuser'));

Now your URL to /user would be

$myuserurl = URL::to('/myuser');echo $myuserurl; // would be http://baseurl/user

I hope this helps you. Pls refer http://laravel.com/docs/routing#named-routes