vitasya
vitasya

Reputation: 355

Laravel single application but for front and admin area

If I will create some application on Laravel (for example it will be project.com) and in this same application I will develop admin area (with ACL, users management, etc.). Can I use it like project.com for front-side but backoffice.project.com for admin area in same application? Thanks.

Upvotes: 0

Views: 873

Answers (2)

Mauricio Rodrigues
Mauricio Rodrigues

Reputation: 807

You can maintain both applications in the same Laravel project and use grouped routes and filter your routes by domain.

Route::group(['domain' => 'backoffice.project.com'], function () {
   // your BACKEND routes...
});

Route::group(['domain' => 'www.project.com'], function () {
   // your FRONTEND routes...
});

You can complement the route comportment with middleware too.

// in this case all backend routes will be passed to auth middleware.
Route::group(['domain' => 'backoffice.project.com', 'middleware' => 'auth'], function () {
   // your BACKEND routes...
});

Important:

Observe that the Laravel documentation talk about Sub-Domains Routing. In this case, the approach of the documentation is the use of dynamic subdomains, as can be seen in the following example.

Route::domain('{account}.myapp.com')->group(function () {
    Route::get('user/{id}', function ($account, $id) {
        //
    });
});

In this case, {account} is a route parameter that can be used inside of the route group.

You can see (and read) more about Laravel routes here: https://laravel.com/docs/5.5/routing

Upvotes: 2

Camilo
Camilo

Reputation: 7184

Yes, you can group routes by domain.

Since Laravel 5.3 you can group them like this:

Route::domain('project.com')->group(function () {
    // Your frontend routes
});

Route::domain('backoffice.project.com')->group(function () {
    // Your backend routes
});

Before Laravel 5.3 you can group them like this:

Route::group(['domain' => 'project.com'], function () {
    // You frontend routes
});

Route::group(['domain' => 'backoffice.project.com'], function () {
    // You backend routes
});

Upvotes: 0

Related Questions