Hi, when a route has parameters, you can enter them like below, each key is the parameter name of your route parameter. http://laravel.com/docs/helpers#urls
URL::route('routename', array('subdom' => 'your-subdomain'))
Edwin-Luijten said:
Hi, when a route has parameters, you can enter them like below, each key is the parameter name of your route parameter. http://laravel.com/docs/helpers#urls
URL::route('routename', array('subdom' => 'your-subdomain'))
Hi Edwin, thank you for your reply. Your solution WORKS, but...
Is there a way to make URL::route('routename') to include subdomain automatically?
If I use your approach, then I have to include the 2nd parameter in all of my blades/templates for all links
(Example: <li><a href="{{ URL::route('routename', $subdom) }}">some link</a></li>
In addition, I have to pass $subdom to all Controller functions in my project such as:
class HomeController extends BaseController {
public function home($subdom){
return View::make('home')
->with('subdom', $subdom);
}
}
Is there any way to avoid the passing of $subdom parameter to all Controller functions?
My apologies for asking dumb questions, I just started with Laravel...
I would suggest using a intermediary route function where the subdomain will be set by default. This way you won't have to give the subdomain parameter for each route. The downside is you will have to find/replace the current used route() calls to this custom one. Something like this should do the trick:
function subRoute($route, $params = array())
{
// retrieve current subdomain if none passed
if(!isset($params['subdomain'])
{
$params['subdomain'] = array_shift(explode(".",Request::server('HTTP_HOST')));
}
return route($route,$params);
}
BenCavens said:
I would suggest using a intermediary route function where the subdomain will be set by default. This way you won't have to give the subdomain parameter for each route. The downside is you will have to find/replace the current used route() calls to this custom one. Something like this should do the trick:
function subRoute($route, $params = array()) { // retrieve current subdomain if none passed if(!isset($params['subdomain']) { $params['subdomain'] = array_shift(explode(".",Request::server('HTTP_HOST'))); } return route($route,$params); }
Ben, thank you for the reply. This function will still add an extra layer of maintenance because we would not be calling builtin URL::route(...) method in our templates/blades.
Is it possible to override the URL::route()?
Thanks again to everyone for trying to help the Laravel beginner.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community