DEV Community


Discussion on: How can I make a good structure in laravel project ?

lito profile image

I'm using a domain design in my projects.

The app folder contains the Domains folder with all related domains. Every Model is a domain (and some other non models contents like Dashboard).

Domain Scaffolding

Every domain include his own router.php like app/Domains/Exchange/Controller/router.php:

<?php declare(strict_types=1);

namespace App\Domains\Exchange\Controller;

use Illuminate\Support\Facades\Route;

Route::group(['middleware' => ['user.auth']], static function () {
    Route::get('/exchange', Index::class)->name('exchange.index');
    Route::get('/exchange/{product_id}', Detail::class)->name('exchange.detail');
Enter fullscreen mode Exit fullscreen mode

All routers are loaded from a main app/Http/router.php file:

<?php declare(strict_types=1);

foreach (glob(app_path('Domains/*/Controller*/router.php')) as $file) {
    require $file;
Enter fullscreen mode Exit fullscreen mode

Domain Controller folder is the default Controller type on project, sometimes API and sometimes Web. Also you can create more alternative controllers folders like ControllerApi and ControllerWeb.

Also every domain include his own resources/views/domain folder:

Domain Scaffolding

And this is my point of view :)