Support the ongoing development of Laravel.io →
Configuration Requests
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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...

Question 1:

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

Question 2

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...

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.