3

I'm building a multi-site project, each site with different domain, for example "site-two.com", "site-one.net".

I have been searching, but it's not clear for me how to do it, also if it's possible to do it?

I found this example on Laracasts, but I don't understand it:

// routes.php
Route::group(['domain' => '{projectSlug}.{tld}'], function($projectSlug)
{
 // Website routes
});

// bindings.php
Route::bind('projectSlug', function($value, $route)
{
 return Project::where('slug', '=', $value)->firstOrFail(); 
});

Route::bind('tld', function($value, $route)
{
 $project = $route->getParameter('projectSlug'); 

 if($project->tld !== $value)
    App::abort(404);

 return $value;
});

// When creating a URL to a route
route('project/home', [$project->slug, $project->tld]);

I also found something simpler on reddit, but I would like to know if this is totally functional, I mean when the domain X is in the browser I'll only have access to the group routes?

Route::group(array('domain' => 'site-one.com'), function() {
    /* routes here */
    Route::get('/{link_slug}', 'Controller@something');
});

Route::group(array('domain' => 'site-two.com'), function() {
        /* routes here */
        Route::get('/{link_slug}', 'Controller@something');
    });

What could be a great approach of the file structure when having a multi-site project?, a site folder under controller, model, views ... ?

Jonathan Solorzano
  • 6,812
  • 20
  • 70
  • 131
  • any info what you didnt understand? just change 'site-one' with you first domain and 'site-two' with second domain – Amir Bar Aug 02 '15 at 18:18
  • The second example is what i understand, but the first one seems very complicated, why? i read the explanation and he can handle many sites in one laravel project, he said he had like 40 sites – Jonathan Solorzano Aug 02 '15 at 18:22
  • It's easy to handle subdomains with Laravel. But for the different domains, it's difficult. I am also searching for a solution to handle multiple domains. Please share I you got a solution. – Utkarsh Pandey Dec 30 '18 at 12:31

0 Answers0