2

Here is my route:

Route::group(array('domain'=>'{subdomain}.example.com'), function()  
{
    Route::group(array('before'=>array('authenticate')), function()
    {
        Route::resource('post', 'PostController');

        Route::resource('comments', 'CommentsController');

        Route::resource('forum', 'ForumController');

        Route::resource('users', 'UsersController');

    });
});

It seems that by default ALL my resource controllers are now taking the subdomain as first parameter and I can't find a way to change it.

If possible, I'd like to ignore the subdomain entirely.

Example use cases:

admin.example.com/forum/1?domain=foo

foo.example.com/forum/1

bar.example.com/forum/2

This site hosts 2 forums, but there is only 1 admin managing all of them. For admin to access the forum foo, admin must also supply domain=foo to look at it.

4
  • Can you post the rest of your routes file? I dont see any other resource controllers other than PostController? Commented May 20, 2014 at 3:20
  • @TheShiftExchange I've added all of them in Commented May 20, 2014 at 3:23
  • Route::group(array('domain'=>'admin.example.com') you can use the rule for admin separately before oute::group(array('domain'=>'{subdomain}.example.com') rule. Commented May 20, 2014 at 3:54
  • @AmitGarg yes, but it seems quite ugly if I have to copy all those resource controllers again for each of those route domain. Commented May 20, 2014 at 4:03

1 Answer 1

6

If you dont want to route based on the subdomain, then you should only filter the subdomain for access.

Route::filter('subdomain', function($route, $request) 
{
    $host = $request->getHost();
    $parts = explode('.', $host);
    $subdomain = $parts[0];

    if ($subdomain == 'something')
    {
         // Allow or deny
    }
});


Route::group(array('before'=>array('subdomain|authenticate')), function()
    {
        Route::resource('post', 'PostController');

        Route::resource('comments', 'CommentsController');

        Route::resource('forum', 'ForumController');

        Route::resource('users', 'UsersController');

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

6 Comments

I might not be clear enough. I need to use subdomains for all routes because both normal users and admins will be accessing the same routes. But the subdomain parameter is not important to the functions at all, they just trigger different authentication.
Yeah - sorry your not being clear enough to me - I dont understand. Can you please provide some further examples in your question to expand more.
oh wait - i get it now - give me 2 mins - i'll change my answer
I've added example use cases in the original question. Hope it's clear enough.
Try that - see if it helps.
|

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.