├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── README.md ├── _ide_helper.php ├── app ├── Http │ └── Controllers │ │ └── Controller.php ├── Models │ └── User.php └── Providers │ └── AppServiceProvider.php ├── artisan ├── bootstrap ├── app.php ├── cache │ └── .gitignore └── providers.php ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── cache.php ├── database.php ├── filesystems.php ├── logging.php ├── mail.php ├── queue.php ├── services.php └── session.php ├── database ├── .gitignore ├── factories │ └── UserFactory.php ├── migrations │ ├── 0001_01_01_000000_create_users_table.php │ ├── 0001_01_01_000001_create_cache_table.php │ ├── 0001_01_01_000002_create_jobs_table.php │ ├── 2024_04_27_171052_create_blog_comments_table.php │ └── 2024_04_27_171052_create_blog_posts_table.php └── seeders │ └── DatabaseSeeder.php ├── package.json ├── phpunit.xml ├── public ├── .htaccess ├── favicon.ico ├── index.php └── robots.txt ├── resources ├── css │ └── app.css ├── js │ ├── app.js │ └── bootstrap.js └── views │ └── welcome.blade.php ├── routes ├── console.php └── web.php ├── src ├── Blog │ ├── Application │ │ ├── Command │ │ │ ├── CreateCommentCommandHandler.php │ │ │ ├── CreatePostCommandHandler.php │ │ │ ├── UpdateCommentCommandHandler.php │ │ │ └── UpdatePostCommandHandler.php │ │ ├── Exception │ │ │ └── SlugAlreadyExistedException.php │ │ ├── Payload │ │ │ ├── CreateCommentPayload.php │ │ │ ├── CreatePostPayload.php │ │ │ ├── FindPostPayload.php │ │ │ ├── GetPostsPayload.php │ │ │ ├── UpdateCommentPayload.php │ │ │ └── UpdatePostPayload.php │ │ ├── Query │ │ │ ├── FindPostQueryHandler.php │ │ │ └── GetPostsQueryHandler.php │ │ └── Repository │ │ │ ├── PostQueryInterfaceRepository.php │ │ │ └── PostWriteInterfaceRepository.php │ ├── BlogProvider.php │ ├── Domain │ │ ├── Aggregate │ │ │ ├── CommentCollection.php │ │ │ └── PostAggregate.php │ │ ├── Entity │ │ │ └── CommentEntity.php │ │ └── ValueObject │ │ │ ├── CommentContent.php │ │ │ ├── CommentId.php │ │ │ ├── PostContent.php │ │ │ ├── PostId.php │ │ │ ├── PostSlug.php │ │ │ └── PostTitle.php │ ├── Infrastructure │ │ ├── Model │ │ │ ├── Comment.php │ │ │ └── Post.php │ │ └── Repository │ │ │ └── Mysql │ │ │ ├── PostQueryRepository.php │ │ │ └── PostWriteRepository.php │ └── Presentation │ │ ├── Api │ │ ├── PostController.php │ │ └── ViewModel │ │ │ ├── CommentViewModel.php │ │ │ └── PostViewModel.php │ │ ├── Cli │ │ └── .gitignore │ │ └── Http │ │ └── .gitignore └── Shared │ ├── Application │ └── CommandBusInterface.php │ ├── Domain │ ├── Entity │ │ └── HasKeyInterface.php │ └── ValueObject │ │ ├── IntValue.php │ │ ├── KeyValueCollection.php │ │ └── StringValue.php │ ├── Exception │ ├── DomainException.php │ ├── ExceptionUtil.php │ └── ValueObject │ │ ├── NumberOverMaxException.php │ │ ├── NumberOverMinException.php │ │ └── StringToLongException.php │ ├── Infrastructure │ └── CommandBus.php │ ├── SharedProvider.php │ └── Slug.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ ├── .gitignore │ │ └── data │ │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tests ├── Blog │ └── Application │ │ └── Command │ │ └── CreateCommentCommandHandlerTest.php ├── Feature │ └── ExampleTest.php ├── TestCase.php └── Unit │ └── ExampleTest.php └── vite.config.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | 17 | [docker-compose.yml] 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_TIMEZONE=UTC 6 | APP_URL=http://localhost 7 | 8 | APP_LOCALE=en 9 | APP_FALLBACK_LOCALE=en 10 | APP_FAKER_LOCALE=en_US 11 | 12 | APP_MAINTENANCE_DRIVER=file 13 | APP_MAINTENANCE_STORE=database 14 | 15 | BCRYPT_ROUNDS=12 16 | 17 | LOG_CHANNEL=stack 18 | LOG_STACK=single 19 | LOG_DEPRECATIONS_CHANNEL=null 20 | LOG_LEVEL=debug 21 | 22 | DB_CONNECTION=sqlite 23 | # DB_HOST=127.0.0.1 24 | # DB_PORT=3306 25 | # DB_DATABASE=laravel 26 | # DB_USERNAME=root 27 | # DB_PASSWORD= 28 | 29 | SESSION_DRIVER=database 30 | SESSION_LIFETIME=120 31 | SESSION_ENCRYPT=false 32 | SESSION_PATH=/ 33 | SESSION_DOMAIN=null 34 | 35 | BROADCAST_CONNECTION=log 36 | FILESYSTEM_DISK=local 37 | QUEUE_CONNECTION=database 38 | 39 | CACHE_STORE=database 40 | CACHE_PREFIX= 41 | 42 | MEMCACHED_HOST=127.0.0.1 43 | 44 | REDIS_CLIENT=phpredis 45 | REDIS_HOST=127.0.0.1 46 | REDIS_PASSWORD=null 47 | REDIS_PORT=6379 48 | 49 | MAIL_MAILER=log 50 | MAIL_HOST=127.0.0.1 51 | MAIL_PORT=2525 52 | MAIL_USERNAME=null 53 | MAIL_PASSWORD=null 54 | MAIL_ENCRYPTION=null 55 | MAIL_FROM_ADDRESS="hello@example.com" 56 | MAIL_FROM_NAME="${APP_NAME}" 57 | 58 | AWS_ACCESS_KEY_ID= 59 | AWS_SECRET_ACCESS_KEY= 60 | AWS_DEFAULT_REGION=us-east-1 61 | AWS_BUCKET= 62 | AWS_USE_PATH_STYLE_ENDPOINT=false 63 | 64 | VITE_APP_NAME="${APP_NAME}" 65 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | *.blade.php diff=html 4 | *.css diff=css 5 | *.html diff=html 6 | *.md diff=markdown 7 | *.php diff=php 8 | 9 | /.github export-ignore 10 | CHANGELOG.md export-ignore 11 | .styleci.yml export-ignore 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.phpunit.cache 2 | /node_modules 3 | /public/build 4 | /public/hot 5 | /public/storage 6 | /storage/*.key 7 | /vendor 8 | .env 9 | .env.backup 10 | .env.production 11 | .phpunit.result.cache 12 | Homestead.json 13 | Homestead.yaml 14 | auth.json 15 | npm-debug.log 16 | yarn-error.log 17 | /.fleet 18 | /.idea 19 | /.vscode 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Laravel Clean Architecture and DDD example 2 | This project is a simple demo applying the following technologies with Laravel 3 | + Clean Architecture 4 | + Domain Driven Design 5 | + Command Bus 6 | + CQRS 7 | 8 | ## Projects structures 9 | ```sh 10 | ├── Blog 11 | │ ├── Application 12 | │ │ ├── Command 13 | │ │ │ ├── CreateCommentCommandHandler.php 14 | │ │ │ ├── CreatePostCommandHandler.php 15 | │ │ │ ├── UpdateCommentCommandHandler.php 16 | │ │ │ └── UpdatePostCommandHandler.php 17 | │ │ ├── Exception 18 | │ │ │ └── SlugAlreadyExistedException.php 19 | │ │ ├── Payload 20 | │ │ │ ├── CreateCommentPayload.php 21 | │ │ │ ├── CreatePostPayload.php 22 | │ │ │ ├── FindPostPayload.php 23 | │ │ │ ├── GetPostsPayload.php 24 | │ │ │ ├── UpdateCommentPayload.php 25 | │ │ │ └── UpdatePostPayload.php 26 | │ │ ├── Query 27 | │ │ │ ├── FindPostQueryHandler.php 28 | │ │ │ └── GetPostsQueryHandler.php 29 | │ │ └── Repository 30 | │ │ ├── PostQueryInterfaceRepository.php 31 | │ │ └── PostWriteInterfaceRepository.php 32 | │ ├── BlogProvider.php 33 | │ ├── Domain 34 | │ │ ├── Aggregate 35 | │ │ │ ├── CommentCollection.php 36 | │ │ │ └── PostAggregate.php 37 | │ │ ├── Entity 38 | │ │ │ └── CommentEntity.php 39 | │ │ └── ValueObject 40 | │ │ ├── CommentContent.php 41 | │ │ ├── CommentId.php 42 | │ │ ├── PostContent.php 43 | │ │ ├── PostId.php 44 | │ │ ├── PostSlug.php 45 | │ │ └── PostTitle.php 46 | │ ├── Infrastructure 47 | │ │ ├── Model 48 | │ │ │ ├── Comment.php 49 | │ │ │ └── Post.php 50 | │ │ └── Repository 51 | │ │ └── Mysql 52 | │ │ ├── PostQueryRepository.php 53 | │ │ └── PostWriteRepository.php 54 | │ └── Presentation 55 | │ ├── Api 56 | │ │ ├── PostController.php 57 | │ │ └── ViewModel 58 | │ │ ├── CommentViewModel.php 59 | │ │ └── PostViewModel.php 60 | │ ├── Cli 61 | │ └── Http 62 | └── Shared 63 | ├── Application 64 | │ └── CommandBusInterface.php 65 | ├── Domain 66 | │ ├── Entity 67 | │ │ └── HasKeyInterface.php 68 | │ └── ValueObject 69 | │ ├── IntValue.php 70 | │ ├── KeyValueCollection.php 71 | │ └── StringValue.php 72 | ├── Exception 73 | │ ├── DomainException.php 74 | │ ├── ExceptionUtil.php 75 | │ └── ValueObject 76 | │ ├── ValueOverMaxException.php 77 | │ ├── ValueOverMinException.php 78 | │ └── ValueToLongException.php 79 | ├── Infrastructure 80 | │ └── CommandBus.php 81 | ├── SharedProvider.php 82 | └── Slug.php 83 | ``` 84 | 85 | ## Contributing 86 | 87 | Thank you for considering contributing to the example. 88 | 89 | ## License 90 | 91 | The example is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). 92 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | $notifications 22 | * @property-read int|null $notifications_count 23 | * @method static \Database\Factories\UserFactory factory($count = null, $state = []) 24 | * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery() 25 | * @method static \Illuminate\Database\Eloquent\Builder|User newQuery() 26 | * @method static \Illuminate\Database\Eloquent\Builder|User query() 27 | * @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value) 28 | * @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value) 29 | * @method static \Illuminate\Database\Eloquent\Builder|User whereEmailVerifiedAt($value) 30 | * @method static \Illuminate\Database\Eloquent\Builder|User whereId($value) 31 | * @method static \Illuminate\Database\Eloquent\Builder|User whereName($value) 32 | * @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value) 33 | * @method static \Illuminate\Database\Eloquent\Builder|User whereRememberToken($value) 34 | * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value) 35 | * @mixin \Eloquent 36 | */ 37 | class User extends Authenticatable 38 | { 39 | use HasFactory, Notifiable; 40 | 41 | /** 42 | * The attributes that are mass assignable. 43 | * 44 | * @var array 45 | */ 46 | protected $fillable = [ 47 | 'name', 48 | 'email', 49 | 'password', 50 | ]; 51 | 52 | /** 53 | * The attributes that should be hidden for serialization. 54 | * 55 | * @var array 56 | */ 57 | protected $hidden = [ 58 | 'password', 59 | 'remember_token', 60 | ]; 61 | 62 | /** 63 | * Get the attributes that should be cast. 64 | * 65 | * @return array 66 | */ 67 | protected function casts(): array 68 | { 69 | return [ 70 | 'email_verified_at' => 'datetime', 71 | 'password' => 'hashed', 72 | ]; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | handleCommand(new ArgvInput); 14 | 15 | exit($status); 16 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | withRouting( 9 | web: __DIR__.'/../routes/web.php', 10 | commands: __DIR__.'/../routes/console.php', 11 | health: '/up', 12 | ) 13 | ->withMiddleware(function (Middleware $middleware) { 14 | // 15 | }) 16 | ->withExceptions(function (Exceptions $exceptions) { 17 | // 18 | })->create(); 19 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /bootstrap/providers.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Application Environment 21 | |-------------------------------------------------------------------------- 22 | | 23 | | This value determines the "environment" your application is currently 24 | | running in. This may determine how you prefer to configure various 25 | | services the application utilizes. Set this in your ".env" file. 26 | | 27 | */ 28 | 29 | 'env' => env('APP_ENV', 'production'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Application Debug Mode 34 | |-------------------------------------------------------------------------- 35 | | 36 | | When your application is in debug mode, detailed error messages with 37 | | stack traces will be shown on every error that occurs within your 38 | | application. If disabled, a simple generic error page is shown. 39 | | 40 | */ 41 | 42 | 'debug' => (bool) env('APP_DEBUG', false), 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Application URL 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This URL is used by the console to properly generate URLs when using 50 | | the Artisan command line tool. You should set this to the root of 51 | | the application so that it's available within Artisan commands. 52 | | 53 | */ 54 | 55 | 'url' => env('APP_URL', 'http://localhost'), 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Application Timezone 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may specify the default timezone for your application, which 63 | | will be used by the PHP date and date-time functions. The timezone 64 | | is set to "UTC" by default as it is suitable for most use cases. 65 | | 66 | */ 67 | 68 | 'timezone' => env('APP_TIMEZONE', 'UTC'), 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Application Locale Configuration 73 | |-------------------------------------------------------------------------- 74 | | 75 | | The application locale determines the default locale that will be used 76 | | by Laravel's translation / localization methods. This option can be 77 | | set to any locale for which you plan to have translation strings. 78 | | 79 | */ 80 | 81 | 'locale' => env('APP_LOCALE', 'en'), 82 | 83 | 'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'), 84 | 85 | 'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'), 86 | 87 | /* 88 | |-------------------------------------------------------------------------- 89 | | Encryption Key 90 | |-------------------------------------------------------------------------- 91 | | 92 | | This key is utilized by Laravel's encryption services and should be set 93 | | to a random, 32 character string to ensure that all encrypted values 94 | | are secure. You should do this prior to deploying the application. 95 | | 96 | */ 97 | 98 | 'cipher' => 'AES-256-CBC', 99 | 100 | 'key' => env('APP_KEY'), 101 | 102 | 'previous_keys' => [ 103 | ...array_filter( 104 | explode(',', env('APP_PREVIOUS_KEYS', '')) 105 | ), 106 | ], 107 | 108 | /* 109 | |-------------------------------------------------------------------------- 110 | | Maintenance Mode Driver 111 | |-------------------------------------------------------------------------- 112 | | 113 | | These configuration options determine the driver used to determine and 114 | | manage Laravel's "maintenance mode" status. The "cache" driver will 115 | | allow maintenance mode to be controlled across multiple machines. 116 | | 117 | | Supported drivers: "file", "cache" 118 | | 119 | */ 120 | 121 | 'maintenance' => [ 122 | 'driver' => env('APP_MAINTENANCE_DRIVER', 'file'), 123 | 'store' => env('APP_MAINTENANCE_STORE', 'database'), 124 | ], 125 | 126 | ]; 127 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => env('AUTH_GUARD', 'web'), 18 | 'passwords' => env('AUTH_PASSWORD_BROKER', 'users'), 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | which utilizes session storage plus the Eloquent user provider. 29 | | 30 | | All authentication guards have a user provider, which defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | system used by the application. Typically, Eloquent is utilized. 33 | | 34 | | Supported: "session" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | ], 44 | 45 | /* 46 | |-------------------------------------------------------------------------- 47 | | User Providers 48 | |-------------------------------------------------------------------------- 49 | | 50 | | All authentication guards have a user provider, which defines how the 51 | | users are actually retrieved out of your database or other storage 52 | | system used by the application. Typically, Eloquent is utilized. 53 | | 54 | | If you have multiple user tables or models you may configure multiple 55 | | providers to represent the model / table. These providers may then 56 | | be assigned to any extra authentication guards you have defined. 57 | | 58 | | Supported: "database", "eloquent" 59 | | 60 | */ 61 | 62 | 'providers' => [ 63 | 'users' => [ 64 | 'driver' => 'eloquent', 65 | 'model' => env('AUTH_MODEL', App\Models\User::class), 66 | ], 67 | 68 | // 'users' => [ 69 | // 'driver' => 'database', 70 | // 'table' => 'users', 71 | // ], 72 | ], 73 | 74 | /* 75 | |-------------------------------------------------------------------------- 76 | | Resetting Passwords 77 | |-------------------------------------------------------------------------- 78 | | 79 | | These configuration options specify the behavior of Laravel's password 80 | | reset functionality, including the table utilized for token storage 81 | | and the user provider that is invoked to actually retrieve users. 82 | | 83 | | The expiry time is the number of minutes that each reset token will be 84 | | considered valid. This security feature keeps tokens short-lived so 85 | | they have less time to be guessed. You may change this as needed. 86 | | 87 | | The throttle setting is the number of seconds a user must wait before 88 | | generating more password reset tokens. This prevents the user from 89 | | quickly generating a very large amount of password reset tokens. 90 | | 91 | */ 92 | 93 | 'passwords' => [ 94 | 'users' => [ 95 | 'provider' => 'users', 96 | 'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'), 97 | 'expire' => 60, 98 | 'throttle' => 60, 99 | ], 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Password Confirmation Timeout 105 | |-------------------------------------------------------------------------- 106 | | 107 | | Here you may define the amount of seconds before a password confirmation 108 | | window expires and users are asked to re-enter their password via the 109 | | confirmation screen. By default, the timeout lasts for three hours. 110 | | 111 | */ 112 | 113 | 'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800), 114 | 115 | ]; 116 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_STORE', 'database'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | | Supported drivers: "apc", "array", "database", "file", "memcached", 30 | | "redis", "dynamodb", "octane", "null" 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'array' => [ 37 | 'driver' => 'array', 38 | 'serialize' => false, 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'table' => env('DB_CACHE_TABLE', 'cache'), 44 | 'connection' => env('DB_CACHE_CONNECTION'), 45 | 'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'), 46 | ], 47 | 48 | 'file' => [ 49 | 'driver' => 'file', 50 | 'path' => storage_path('framework/cache/data'), 51 | 'lock_path' => storage_path('framework/cache/data'), 52 | ], 53 | 54 | 'memcached' => [ 55 | 'driver' => 'memcached', 56 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 57 | 'sasl' => [ 58 | env('MEMCACHED_USERNAME'), 59 | env('MEMCACHED_PASSWORD'), 60 | ], 61 | 'options' => [ 62 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 63 | ], 64 | 'servers' => [ 65 | [ 66 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 67 | 'port' => env('MEMCACHED_PORT', 11211), 68 | 'weight' => 100, 69 | ], 70 | ], 71 | ], 72 | 73 | 'redis' => [ 74 | 'driver' => 'redis', 75 | 'connection' => env('REDIS_CACHE_CONNECTION', 'cache'), 76 | 'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'), 77 | ], 78 | 79 | 'dynamodb' => [ 80 | 'driver' => 'dynamodb', 81 | 'key' => env('AWS_ACCESS_KEY_ID'), 82 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 83 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 84 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 85 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 86 | ], 87 | 88 | 'octane' => [ 89 | 'driver' => 'octane', 90 | ], 91 | 92 | ], 93 | 94 | /* 95 | |-------------------------------------------------------------------------- 96 | | Cache Key Prefix 97 | |-------------------------------------------------------------------------- 98 | | 99 | | When utilizing the APC, database, memcached, Redis, and DynamoDB cache 100 | | stores, there might be other applications using the same cache. For 101 | | that reason, you may prefix every cache key to avoid collisions. 102 | | 103 | */ 104 | 105 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'), 106 | 107 | ]; 108 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'sqlite'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Database Connections 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Below are all of the database connections defined for your application. 27 | | An example configuration is provided for each database system which 28 | | is supported by Laravel. You're free to add / remove connections. 29 | | 30 | */ 31 | 32 | 'connections' => [ 33 | 34 | 'sqlite' => [ 35 | 'driver' => 'sqlite', 36 | 'url' => env('DB_URL'), 37 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 38 | 'prefix' => '', 39 | 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 40 | ], 41 | 42 | 'mysql' => [ 43 | 'driver' => 'mysql', 44 | 'url' => env('DB_URL'), 45 | 'host' => env('DB_HOST', '127.0.0.1'), 46 | 'port' => env('DB_PORT', '3306'), 47 | 'database' => env('DB_DATABASE', 'laravel'), 48 | 'username' => env('DB_USERNAME', 'root'), 49 | 'password' => env('DB_PASSWORD', ''), 50 | 'unix_socket' => env('DB_SOCKET', ''), 51 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 52 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 53 | 'prefix' => '', 54 | 'prefix_indexes' => true, 55 | 'strict' => true, 56 | 'engine' => null, 57 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 58 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 59 | ]) : [], 60 | ], 61 | 62 | 'mariadb' => [ 63 | 'driver' => 'mariadb', 64 | 'url' => env('DB_URL'), 65 | 'host' => env('DB_HOST', '127.0.0.1'), 66 | 'port' => env('DB_PORT', '3306'), 67 | 'database' => env('DB_DATABASE', 'laravel'), 68 | 'username' => env('DB_USERNAME', 'root'), 69 | 'password' => env('DB_PASSWORD', ''), 70 | 'unix_socket' => env('DB_SOCKET', ''), 71 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 72 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 73 | 'prefix' => '', 74 | 'prefix_indexes' => true, 75 | 'strict' => true, 76 | 'engine' => null, 77 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 78 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 79 | ]) : [], 80 | ], 81 | 82 | 'pgsql' => [ 83 | 'driver' => 'pgsql', 84 | 'url' => env('DB_URL'), 85 | 'host' => env('DB_HOST', '127.0.0.1'), 86 | 'port' => env('DB_PORT', '5432'), 87 | 'database' => env('DB_DATABASE', 'laravel'), 88 | 'username' => env('DB_USERNAME', 'root'), 89 | 'password' => env('DB_PASSWORD', ''), 90 | 'charset' => env('DB_CHARSET', 'utf8'), 91 | 'prefix' => '', 92 | 'prefix_indexes' => true, 93 | 'search_path' => 'public', 94 | 'sslmode' => 'prefer', 95 | ], 96 | 97 | 'sqlsrv' => [ 98 | 'driver' => 'sqlsrv', 99 | 'url' => env('DB_URL'), 100 | 'host' => env('DB_HOST', 'localhost'), 101 | 'port' => env('DB_PORT', '1433'), 102 | 'database' => env('DB_DATABASE', 'laravel'), 103 | 'username' => env('DB_USERNAME', 'root'), 104 | 'password' => env('DB_PASSWORD', ''), 105 | 'charset' => env('DB_CHARSET', 'utf8'), 106 | 'prefix' => '', 107 | 'prefix_indexes' => true, 108 | // 'encrypt' => env('DB_ENCRYPT', 'yes'), 109 | // 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'), 110 | ], 111 | 112 | ], 113 | 114 | /* 115 | |-------------------------------------------------------------------------- 116 | | Migration Repository Table 117 | |-------------------------------------------------------------------------- 118 | | 119 | | This table keeps track of all the migrations that have already run for 120 | | your application. Using this information, we can determine which of 121 | | the migrations on disk haven't actually been run on the database. 122 | | 123 | */ 124 | 125 | 'migrations' => [ 126 | 'table' => 'migrations', 127 | 'update_date_on_publish' => true, 128 | ], 129 | 130 | /* 131 | |-------------------------------------------------------------------------- 132 | | Redis Databases 133 | |-------------------------------------------------------------------------- 134 | | 135 | | Redis is an open source, fast, and advanced key-value store that also 136 | | provides a richer body of commands than a typical key-value system 137 | | such as Memcached. You may define your connection settings here. 138 | | 139 | */ 140 | 141 | 'redis' => [ 142 | 143 | 'client' => env('REDIS_CLIENT', 'phpredis'), 144 | 145 | 'options' => [ 146 | 'cluster' => env('REDIS_CLUSTER', 'redis'), 147 | 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), 148 | ], 149 | 150 | 'default' => [ 151 | 'url' => env('REDIS_URL'), 152 | 'host' => env('REDIS_HOST', '127.0.0.1'), 153 | 'username' => env('REDIS_USERNAME'), 154 | 'password' => env('REDIS_PASSWORD'), 155 | 'port' => env('REDIS_PORT', '6379'), 156 | 'database' => env('REDIS_DB', '0'), 157 | ], 158 | 159 | 'cache' => [ 160 | 'url' => env('REDIS_URL'), 161 | 'host' => env('REDIS_HOST', '127.0.0.1'), 162 | 'username' => env('REDIS_USERNAME'), 163 | 'password' => env('REDIS_PASSWORD'), 164 | 'port' => env('REDIS_PORT', '6379'), 165 | 'database' => env('REDIS_CACHE_DB', '1'), 166 | ], 167 | 168 | ], 169 | 170 | ]; 171 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DISK', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Filesystem Disks 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Below you may configure as many filesystem disks as necessary, and you 24 | | may even configure multiple disks for the same driver. Examples for 25 | | most supported storage drivers are configured here for reference. 26 | | 27 | | Supported Drivers: "local", "ftp", "sftp", "s3" 28 | | 29 | */ 30 | 31 | 'disks' => [ 32 | 33 | 'local' => [ 34 | 'driver' => 'local', 35 | 'root' => storage_path('app'), 36 | 'throw' => false, 37 | ], 38 | 39 | 'public' => [ 40 | 'driver' => 'local', 41 | 'root' => storage_path('app/public'), 42 | 'url' => env('APP_URL').'/storage', 43 | 'visibility' => 'public', 44 | 'throw' => false, 45 | ], 46 | 47 | 's3' => [ 48 | 'driver' => 's3', 49 | 'key' => env('AWS_ACCESS_KEY_ID'), 50 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 51 | 'region' => env('AWS_DEFAULT_REGION'), 52 | 'bucket' => env('AWS_BUCKET'), 53 | 'url' => env('AWS_URL'), 54 | 'endpoint' => env('AWS_ENDPOINT'), 55 | 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 56 | 'throw' => false, 57 | ], 58 | 59 | ], 60 | 61 | /* 62 | |-------------------------------------------------------------------------- 63 | | Symbolic Links 64 | |-------------------------------------------------------------------------- 65 | | 66 | | Here you may configure the symbolic links that will be created when the 67 | | `storage:link` Artisan command is executed. The array keys should be 68 | | the locations of the links and the values should be their targets. 69 | | 70 | */ 71 | 72 | 'links' => [ 73 | public_path('storage') => storage_path('app/public'), 74 | ], 75 | 76 | ]; 77 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Deprecations Log Channel 26 | |-------------------------------------------------------------------------- 27 | | 28 | | This option controls the log channel that should be used to log warnings 29 | | regarding deprecated PHP and library features. This allows you to get 30 | | your application ready for upcoming major versions of dependencies. 31 | | 32 | */ 33 | 34 | 'deprecations' => [ 35 | 'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'), 36 | 'trace' => env('LOG_DEPRECATIONS_TRACE', false), 37 | ], 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Log Channels 42 | |-------------------------------------------------------------------------- 43 | | 44 | | Here you may configure the log channels for your application. Laravel 45 | | utilizes the Monolog PHP logging library, which includes a variety 46 | | of powerful log handlers and formatters that you're free to use. 47 | | 48 | | Available Drivers: "single", "daily", "slack", "syslog", 49 | | "errorlog", "monolog", "custom", "stack" 50 | | 51 | */ 52 | 53 | 'channels' => [ 54 | 55 | 'stack' => [ 56 | 'driver' => 'stack', 57 | 'channels' => explode(',', env('LOG_STACK', 'single')), 58 | 'ignore_exceptions' => false, 59 | ], 60 | 61 | 'single' => [ 62 | 'driver' => 'single', 63 | 'path' => storage_path('logs/laravel.log'), 64 | 'level' => env('LOG_LEVEL', 'debug'), 65 | 'replace_placeholders' => true, 66 | ], 67 | 68 | 'daily' => [ 69 | 'driver' => 'daily', 70 | 'path' => storage_path('logs/laravel.log'), 71 | 'level' => env('LOG_LEVEL', 'debug'), 72 | 'days' => env('LOG_DAILY_DAYS', 14), 73 | 'replace_placeholders' => true, 74 | ], 75 | 76 | 'slack' => [ 77 | 'driver' => 'slack', 78 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 79 | 'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'), 80 | 'emoji' => env('LOG_SLACK_EMOJI', ':boom:'), 81 | 'level' => env('LOG_LEVEL', 'critical'), 82 | 'replace_placeholders' => true, 83 | ], 84 | 85 | 'papertrail' => [ 86 | 'driver' => 'monolog', 87 | 'level' => env('LOG_LEVEL', 'debug'), 88 | 'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class), 89 | 'handler_with' => [ 90 | 'host' => env('PAPERTRAIL_URL'), 91 | 'port' => env('PAPERTRAIL_PORT'), 92 | 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), 93 | ], 94 | 'processors' => [PsrLogMessageProcessor::class], 95 | ], 96 | 97 | 'stderr' => [ 98 | 'driver' => 'monolog', 99 | 'level' => env('LOG_LEVEL', 'debug'), 100 | 'handler' => StreamHandler::class, 101 | 'formatter' => env('LOG_STDERR_FORMATTER'), 102 | 'with' => [ 103 | 'stream' => 'php://stderr', 104 | ], 105 | 'processors' => [PsrLogMessageProcessor::class], 106 | ], 107 | 108 | 'syslog' => [ 109 | 'driver' => 'syslog', 110 | 'level' => env('LOG_LEVEL', 'debug'), 111 | 'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER), 112 | 'replace_placeholders' => true, 113 | ], 114 | 115 | 'errorlog' => [ 116 | 'driver' => 'errorlog', 117 | 'level' => env('LOG_LEVEL', 'debug'), 118 | 'replace_placeholders' => true, 119 | ], 120 | 121 | 'null' => [ 122 | 'driver' => 'monolog', 123 | 'handler' => NullHandler::class, 124 | ], 125 | 126 | 'emergency' => [ 127 | 'path' => storage_path('logs/laravel.log'), 128 | ], 129 | 130 | ], 131 | 132 | ]; 133 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_MAILER', 'log'), 18 | 19 | /* 20 | |-------------------------------------------------------------------------- 21 | | Mailer Configurations 22 | |-------------------------------------------------------------------------- 23 | | 24 | | Here you may configure all of the mailers used by your application plus 25 | | their respective settings. Several examples have been configured for 26 | | you and you are free to add your own as your application requires. 27 | | 28 | | Laravel supports a variety of mail "transport" drivers that can be used 29 | | when delivering an email. You may specify which one you're using for 30 | | your mailers below. You may also add additional mailers if needed. 31 | | 32 | | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2", 33 | | "postmark", "log", "array", "failover", "roundrobin" 34 | | 35 | */ 36 | 37 | 'mailers' => [ 38 | 39 | 'smtp' => [ 40 | 'transport' => 'smtp', 41 | 'url' => env('MAIL_URL'), 42 | 'host' => env('MAIL_HOST', '127.0.0.1'), 43 | 'port' => env('MAIL_PORT', 2525), 44 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 45 | 'username' => env('MAIL_USERNAME'), 46 | 'password' => env('MAIL_PASSWORD'), 47 | 'timeout' => null, 48 | 'local_domain' => env('MAIL_EHLO_DOMAIN'), 49 | ], 50 | 51 | 'ses' => [ 52 | 'transport' => 'ses', 53 | ], 54 | 55 | 'postmark' => [ 56 | 'transport' => 'postmark', 57 | // 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'), 58 | // 'client' => [ 59 | // 'timeout' => 5, 60 | // ], 61 | ], 62 | 63 | 'sendmail' => [ 64 | 'transport' => 'sendmail', 65 | 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), 66 | ], 67 | 68 | 'log' => [ 69 | 'transport' => 'log', 70 | 'channel' => env('MAIL_LOG_CHANNEL'), 71 | ], 72 | 73 | 'array' => [ 74 | 'transport' => 'array', 75 | ], 76 | 77 | 'failover' => [ 78 | 'transport' => 'failover', 79 | 'mailers' => [ 80 | 'smtp', 81 | 'log', 82 | ], 83 | ], 84 | 85 | 'roundrobin' => [ 86 | 'transport' => 'roundrobin', 87 | 'mailers' => [ 88 | 'ses', 89 | 'postmark', 90 | ], 91 | ], 92 | 93 | ], 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Global "From" Address 98 | |-------------------------------------------------------------------------- 99 | | 100 | | You may wish for all emails sent by your application to be sent from 101 | | the same address. Here you may specify a name and address that is 102 | | used globally for all emails that are sent by your application. 103 | | 104 | */ 105 | 106 | 'from' => [ 107 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 108 | 'name' => env('MAIL_FROM_NAME', 'Example'), 109 | ], 110 | 111 | ]; 112 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'database'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection options for every queue backend 24 | | used by your application. An example configuration is provided for 25 | | each backend supported by Laravel. You're also free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'connection' => env('DB_QUEUE_CONNECTION'), 40 | 'table' => env('DB_QUEUE_TABLE', 'jobs'), 41 | 'queue' => env('DB_QUEUE', 'default'), 42 | 'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90), 43 | 'after_commit' => false, 44 | ], 45 | 46 | 'beanstalkd' => [ 47 | 'driver' => 'beanstalkd', 48 | 'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'), 49 | 'queue' => env('BEANSTALKD_QUEUE', 'default'), 50 | 'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90), 51 | 'block_for' => 0, 52 | 'after_commit' => false, 53 | ], 54 | 55 | 'sqs' => [ 56 | 'driver' => 'sqs', 57 | 'key' => env('AWS_ACCESS_KEY_ID'), 58 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 59 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 60 | 'queue' => env('SQS_QUEUE', 'default'), 61 | 'suffix' => env('SQS_SUFFIX'), 62 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 63 | 'after_commit' => false, 64 | ], 65 | 66 | 'redis' => [ 67 | 'driver' => 'redis', 68 | 'connection' => env('REDIS_QUEUE_CONNECTION', 'default'), 69 | 'queue' => env('REDIS_QUEUE', 'default'), 70 | 'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90), 71 | 'block_for' => null, 72 | 'after_commit' => false, 73 | ], 74 | 75 | ], 76 | 77 | /* 78 | |-------------------------------------------------------------------------- 79 | | Job Batching 80 | |-------------------------------------------------------------------------- 81 | | 82 | | The following options configure the database and table that store job 83 | | batching information. These options can be updated to any database 84 | | connection and table which has been defined by your application. 85 | | 86 | */ 87 | 88 | 'batching' => [ 89 | 'database' => env('DB_CONNECTION', 'sqlite'), 90 | 'table' => 'job_batches', 91 | ], 92 | 93 | /* 94 | |-------------------------------------------------------------------------- 95 | | Failed Queue Jobs 96 | |-------------------------------------------------------------------------- 97 | | 98 | | These options configure the behavior of failed queue job logging so you 99 | | can control how and where failed jobs are stored. Laravel ships with 100 | | support for storing failed jobs in a simple file or in a database. 101 | | 102 | | Supported drivers: "database-uuids", "dynamodb", "file", "null" 103 | | 104 | */ 105 | 106 | 'failed' => [ 107 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), 108 | 'database' => env('DB_CONNECTION', 'sqlite'), 109 | 'table' => 'failed_jobs', 110 | ], 111 | 112 | ]; 113 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'token' => env('POSTMARK_TOKEN'), 19 | ], 20 | 21 | 'ses' => [ 22 | 'key' => env('AWS_ACCESS_KEY_ID'), 23 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 24 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 25 | ], 26 | 27 | 'slack' => [ 28 | 'notifications' => [ 29 | 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'), 30 | 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'), 31 | ], 32 | ], 33 | 34 | ]; 35 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'database'), 22 | 23 | /* 24 | |-------------------------------------------------------------------------- 25 | | Session Lifetime 26 | |-------------------------------------------------------------------------- 27 | | 28 | | Here you may specify the number of minutes that you wish the session 29 | | to be allowed to remain idle before it expires. If you want them 30 | | to expire immediately when the browser is closed then you may 31 | | indicate that via the expire_on_close configuration option. 32 | | 33 | */ 34 | 35 | 'lifetime' => env('SESSION_LIFETIME', 120), 36 | 37 | 'expire_on_close' => env('SESSION_EXPIRE_ON_CLOSE', false), 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Session Encryption 42 | |-------------------------------------------------------------------------- 43 | | 44 | | This option allows you to easily specify that all of your session data 45 | | should be encrypted before it's stored. All encryption is performed 46 | | automatically by Laravel and you may use the session like normal. 47 | | 48 | */ 49 | 50 | 'encrypt' => env('SESSION_ENCRYPT', false), 51 | 52 | /* 53 | |-------------------------------------------------------------------------- 54 | | Session File Location 55 | |-------------------------------------------------------------------------- 56 | | 57 | | When utilizing the "file" session driver, the session files are placed 58 | | on disk. The default storage location is defined here; however, you 59 | | are free to provide another location where they should be stored. 60 | | 61 | */ 62 | 63 | 'files' => storage_path('framework/sessions'), 64 | 65 | /* 66 | |-------------------------------------------------------------------------- 67 | | Session Database Connection 68 | |-------------------------------------------------------------------------- 69 | | 70 | | When using the "database" or "redis" session drivers, you may specify a 71 | | connection that should be used to manage these sessions. This should 72 | | correspond to a connection in your database configuration options. 73 | | 74 | */ 75 | 76 | 'connection' => env('SESSION_CONNECTION'), 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Session Database Table 81 | |-------------------------------------------------------------------------- 82 | | 83 | | When using the "database" session driver, you may specify the table to 84 | | be used to store sessions. Of course, a sensible default is defined 85 | | for you; however, you're welcome to change this to another table. 86 | | 87 | */ 88 | 89 | 'table' => env('SESSION_TABLE', 'sessions'), 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Session Cache Store 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When using one of the framework's cache driven session backends, you may 97 | | define the cache store which should be used to store the session data 98 | | between requests. This must match one of your defined cache stores. 99 | | 100 | | Affects: "apc", "dynamodb", "memcached", "redis" 101 | | 102 | */ 103 | 104 | 'store' => env('SESSION_STORE'), 105 | 106 | /* 107 | |-------------------------------------------------------------------------- 108 | | Session Sweeping Lottery 109 | |-------------------------------------------------------------------------- 110 | | 111 | | Some session drivers must manually sweep their storage location to get 112 | | rid of old sessions from storage. Here are the chances that it will 113 | | happen on a given request. By default, the odds are 2 out of 100. 114 | | 115 | */ 116 | 117 | 'lottery' => [2, 100], 118 | 119 | /* 120 | |-------------------------------------------------------------------------- 121 | | Session Cookie Name 122 | |-------------------------------------------------------------------------- 123 | | 124 | | Here you may change the name of the session cookie that is created by 125 | | the framework. Typically, you should not need to change this value 126 | | since doing so does not grant a meaningful security improvement. 127 | | 128 | */ 129 | 130 | 'cookie' => env( 131 | 'SESSION_COOKIE', 132 | Str::slug(env('APP_NAME', 'laravel'), '_').'_session' 133 | ), 134 | 135 | /* 136 | |-------------------------------------------------------------------------- 137 | | Session Cookie Path 138 | |-------------------------------------------------------------------------- 139 | | 140 | | The session cookie path determines the path for which the cookie will 141 | | be regarded as available. Typically, this will be the root path of 142 | | your application, but you're free to change this when necessary. 143 | | 144 | */ 145 | 146 | 'path' => env('SESSION_PATH', '/'), 147 | 148 | /* 149 | |-------------------------------------------------------------------------- 150 | | Session Cookie Domain 151 | |-------------------------------------------------------------------------- 152 | | 153 | | This value determines the domain and subdomains the session cookie is 154 | | available to. By default, the cookie will be available to the root 155 | | domain and all subdomains. Typically, this shouldn't be changed. 156 | | 157 | */ 158 | 159 | 'domain' => env('SESSION_DOMAIN'), 160 | 161 | /* 162 | |-------------------------------------------------------------------------- 163 | | HTTPS Only Cookies 164 | |-------------------------------------------------------------------------- 165 | | 166 | | By setting this option to true, session cookies will only be sent back 167 | | to the server if the browser has a HTTPS connection. This will keep 168 | | the cookie from being sent to you when it can't be done securely. 169 | | 170 | */ 171 | 172 | 'secure' => env('SESSION_SECURE_COOKIE'), 173 | 174 | /* 175 | |-------------------------------------------------------------------------- 176 | | HTTP Access Only 177 | |-------------------------------------------------------------------------- 178 | | 179 | | Setting this value to true will prevent JavaScript from accessing the 180 | | value of the cookie and the cookie will only be accessible through 181 | | the HTTP protocol. It's unlikely you should disable this option. 182 | | 183 | */ 184 | 185 | 'http_only' => env('SESSION_HTTP_ONLY', true), 186 | 187 | /* 188 | |-------------------------------------------------------------------------- 189 | | Same-Site Cookies 190 | |-------------------------------------------------------------------------- 191 | | 192 | | This option determines how your cookies behave when cross-site requests 193 | | take place, and can be used to mitigate CSRF attacks. By default, we 194 | | will set this value to "lax" to permit secure cross-site requests. 195 | | 196 | | See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value 197 | | 198 | | Supported: "lax", "strict", "none", null 199 | | 200 | */ 201 | 202 | 'same_site' => env('SESSION_SAME_SITE', 'lax'), 203 | 204 | /* 205 | |-------------------------------------------------------------------------- 206 | | Partitioned Cookies 207 | |-------------------------------------------------------------------------- 208 | | 209 | | Setting this value to true will tie the cookie to the top-level site for 210 | | a cross-site context. Partitioned cookies are accepted by the browser 211 | | when flagged "secure" and the Same-Site attribute is set to "none". 212 | | 213 | */ 214 | 215 | 'partitioned' => env('SESSION_PARTITIONED_COOKIE', false), 216 | 217 | ]; 218 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite* 2 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class UserFactory extends Factory 13 | { 14 | /** 15 | * The current password being used by the factory. 16 | */ 17 | protected static ?string $password; 18 | 19 | /** 20 | * Define the model's default state. 21 | * 22 | * @return array 23 | */ 24 | public function definition(): array 25 | { 26 | return [ 27 | 'name' => fake()->name(), 28 | 'email' => fake()->unique()->safeEmail(), 29 | 'email_verified_at' => now(), 30 | 'password' => static::$password ??= Hash::make('password'), 31 | 'remember_token' => Str::random(10), 32 | ]; 33 | } 34 | 35 | /** 36 | * Indicate that the model's email address should be unverified. 37 | */ 38 | public function unverified(): static 39 | { 40 | return $this->state(fn (array $attributes) => [ 41 | 'email_verified_at' => null, 42 | ]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('name'); 17 | $table->string('email')->unique(); 18 | $table->timestamp('email_verified_at')->nullable(); 19 | $table->string('password'); 20 | $table->rememberToken(); 21 | $table->timestamps(); 22 | }); 23 | 24 | Schema::create('password_reset_tokens', function (Blueprint $table) { 25 | $table->string('email')->primary(); 26 | $table->string('token'); 27 | $table->timestamp('created_at')->nullable(); 28 | }); 29 | 30 | Schema::create('sessions', function (Blueprint $table) { 31 | $table->string('id')->primary(); 32 | $table->foreignId('user_id')->nullable()->index(); 33 | $table->string('ip_address', 45)->nullable(); 34 | $table->text('user_agent')->nullable(); 35 | $table->longText('payload'); 36 | $table->integer('last_activity')->index(); 37 | }); 38 | } 39 | 40 | /** 41 | * Reverse the migrations. 42 | */ 43 | public function down(): void 44 | { 45 | Schema::dropIfExists('users'); 46 | Schema::dropIfExists('password_reset_tokens'); 47 | Schema::dropIfExists('sessions'); 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000001_create_cache_table.php: -------------------------------------------------------------------------------- 1 | string('key')->primary(); 16 | $table->mediumText('value'); 17 | $table->integer('expiration'); 18 | }); 19 | 20 | Schema::create('cache_locks', function (Blueprint $table) { 21 | $table->string('key')->primary(); 22 | $table->string('owner'); 23 | $table->integer('expiration'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | */ 30 | public function down(): void 31 | { 32 | Schema::dropIfExists('cache'); 33 | Schema::dropIfExists('cache_locks'); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /database/migrations/0001_01_01_000002_create_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('queue')->index(); 17 | $table->longText('payload'); 18 | $table->unsignedTinyInteger('attempts'); 19 | $table->unsignedInteger('reserved_at')->nullable(); 20 | $table->unsignedInteger('available_at'); 21 | $table->unsignedInteger('created_at'); 22 | }); 23 | 24 | Schema::create('job_batches', function (Blueprint $table) { 25 | $table->string('id')->primary(); 26 | $table->string('name'); 27 | $table->integer('total_jobs'); 28 | $table->integer('pending_jobs'); 29 | $table->integer('failed_jobs'); 30 | $table->longText('failed_job_ids'); 31 | $table->mediumText('options')->nullable(); 32 | $table->integer('cancelled_at')->nullable(); 33 | $table->integer('created_at'); 34 | $table->integer('finished_at')->nullable(); 35 | }); 36 | 37 | Schema::create('failed_jobs', function (Blueprint $table) { 38 | $table->id(); 39 | $table->string('uuid')->unique(); 40 | $table->text('connection'); 41 | $table->text('queue'); 42 | $table->longText('payload'); 43 | $table->longText('exception'); 44 | $table->timestamp('failed_at')->useCurrent(); 45 | }); 46 | } 47 | 48 | /** 49 | * Reverse the migrations. 50 | */ 51 | public function down(): void 52 | { 53 | Schema::dropIfExists('jobs'); 54 | Schema::dropIfExists('job_batches'); 55 | Schema::dropIfExists('failed_jobs'); 56 | } 57 | }; 58 | -------------------------------------------------------------------------------- /database/migrations/2024_04_27_171052_create_blog_comments_table.php: -------------------------------------------------------------------------------- 1 | id(); 15 | $table->foreignId('post_id')->references('id')->on('blog_posts')->onDelete('cascade'); 16 | $table->text('content')->nullable(); 17 | 18 | $table->timestamps(); 19 | $table->softDeletes(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | */ 26 | public function down(): void 27 | { 28 | Schema::drop('blog_comments'); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /database/migrations/2024_04_27_171052_create_blog_posts_table.php: -------------------------------------------------------------------------------- 1 | id(); 15 | $table->string('title')->nullable(); 16 | $table->string('slug', 100)->unique(); 17 | $table->text('content')->nullable(); 18 | 19 | $table->timestamps(); 20 | $table->softDeletes(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | */ 27 | public function down(): void 28 | { 29 | Schema::drop('blog_posts'); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /database/seeders/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | create(); 17 | 18 | User::factory()->create([ 19 | 'name' => 'Test User', 20 | 'email' => 'test@example.com', 21 | ]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "type": "module", 4 | "scripts": { 5 | "dev": "vite", 6 | "build": "vite build" 7 | }, 8 | "devDependencies": { 9 | "axios": "^1.6.4", 10 | "laravel-vite-plugin": "^1.0", 11 | "vite": "^5.0" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | tests/Unit 10 | 11 | 12 | tests/Feature 13 | 14 | 15 | 16 | 17 | app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # Send Requests To Front Controller... 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteCond %{REQUEST_FILENAME} !-f 20 | RewriteRule ^ index.php [L] 21 | 22 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoinv/laravel-clean-ddd/cb3c0444d5bc497671434638198c8934b85a1a31/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | handleRequest(Request::capture()); 18 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /resources/css/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoinv/laravel-clean-ddd/cb3c0444d5bc497671434638198c8934b85a1a31/resources/css/app.css -------------------------------------------------------------------------------- /resources/js/app.js: -------------------------------------------------------------------------------- 1 | import './bootstrap'; 2 | -------------------------------------------------------------------------------- /resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | window.axios = axios; 3 | 4 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 5 | -------------------------------------------------------------------------------- /resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Laravel 8 | 9 | 10 | 11 | 12 | 13 | 14 | 17 | 18 | 19 |
20 | 21 |
22 |
23 |
24 |
25 | 26 |
27 | @if (Route::has('login')) 28 | 54 | @endif 55 |
56 | 57 |
58 | 163 |
164 | 165 |
166 | Laravel v{{ Illuminate\Foundation\Application::VERSION }} (PHP v{{ PHP_VERSION }}) 167 |
168 |
169 |
170 |
171 | 172 | 173 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 8 | })->purpose('Display an inspiring quote')->hourly(); 9 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | queryRepository->findOrFail($payload->postId); 30 | $comment = new CommentEntity(new CommentId(), new CommentContent($payload->content)); 31 | $postAggregate->addComment($comment); 32 | 33 | return $this->writeRepository->save($postAggregate); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Blog/Application/Command/CreatePostCommandHandler.php: -------------------------------------------------------------------------------- 1 | queryRepository->isSlugExists($payload->slug)) { 33 | throw new SlugAlreadyExistedException(); 34 | } 35 | 36 | $postAggregate = new PostAggregate( 37 | new PostId(), 38 | new PostSlug($payload->slug), 39 | new PostTitle($payload->title), 40 | new PostContent($payload->content) 41 | ); 42 | 43 | return $this->writeRepository->save($postAggregate); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Blog/Application/Command/UpdateCommentCommandHandler.php: -------------------------------------------------------------------------------- 1 | queryRepository->findOrFail($payload->postId); 28 | $comment = $postAggregate->findComment($payload->id); 29 | $comment->setContent(new CommentContent($payload->content)); 30 | $postAggregate->updateComment($comment); 31 | 32 | return $this->writeRepository->save($postAggregate); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Blog/Application/Command/UpdatePostCommandHandler.php: -------------------------------------------------------------------------------- 1 | queryRepository->isSlugExists($payload->slug, $payload->id)) { 31 | throw new SlugAlreadyExistedException(); 32 | } 33 | 34 | $postAggregate = $this->queryRepository->findOrFail($payload->id); 35 | $postAggregate->setSlug(new PostSlug($payload->slug)); 36 | $postAggregate->setTitle(new PostTitle($payload->title)); 37 | $postAggregate->setContent(new PostContent($payload->content)); 38 | 39 | return $this->writeRepository->save($postAggregate); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Blog/Application/Exception/SlugAlreadyExistedException.php: -------------------------------------------------------------------------------- 1 | postRepository->findOrFail($payload->postId); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Blog/Application/Query/GetPostsQueryHandler.php: -------------------------------------------------------------------------------- 1 | postRepository->get(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Blog/Application/Repository/PostQueryInterfaceRepository.php: -------------------------------------------------------------------------------- 1 | bind(PostQueryInterfaceRepository::class, PostQueryRepository::class); 29 | app()->bind(PostWriteInterfaceRepository::class, PostWriteRepository::class); 30 | 31 | $bus = app()->make(CommandBusInterface::class); 32 | $bus->map([ 33 | CreateCommentPayload::class => CreateCommentCommandHandler::class, 34 | CreatePostPayload::class => CreatePostCommandHandler::class, 35 | UpdatePostPayload::class => UpdatePostCommandHandler::class, 36 | UpdateCommentPayload::class => UpdateCommentCommandHandler::class, 37 | 38 | FindPostPayload::class => FindPostQueryHandler::class, 39 | GetPostsPayload::class => GetPostsQueryHandler::class, 40 | ]); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Blog/Domain/Aggregate/CommentCollection.php: -------------------------------------------------------------------------------- 1 | comments = new CommentCollection(); 24 | $this->createSlugFromTitle(); 25 | } 26 | 27 | /** 28 | * @throws Throwable 29 | */ 30 | private function createSlugFromTitle(): void 31 | { 32 | if (!$this->slug->getValue() && $this->title->getValue()) { 33 | $this->setSlug(new PostSlug(Slug::slugify($this->title->getValue()))); 34 | } 35 | } 36 | 37 | public function setSlug(PostSlug $slug): self 38 | { 39 | $this->slug = $slug; 40 | 41 | return $this; 42 | } 43 | 44 | public function setId(PostId $id): self 45 | { 46 | $this->id = $id; 47 | 48 | return $this; 49 | } 50 | 51 | public function getSlug(): PostSlug 52 | { 53 | return $this->slug; 54 | } 55 | 56 | public function getTitle(): PostTitle 57 | { 58 | return $this->title; 59 | } 60 | 61 | /** 62 | * @throws Throwable 63 | */ 64 | public function setTitle(PostTitle $title): self 65 | { 66 | $this->title = $title; 67 | $this->createSlugFromTitle(); 68 | 69 | return $this; 70 | } 71 | 72 | public function getContent(): PostContent 73 | { 74 | return $this->content; 75 | } 76 | 77 | public function setContent(PostContent $content): self 78 | { 79 | $this->content = $content; 80 | 81 | return $this; 82 | } 83 | 84 | public function getKey(): string|int|null 85 | { 86 | return $this->getId()->getValue(); 87 | } 88 | 89 | public function getId(): PostId 90 | { 91 | return $this->id; 92 | } 93 | 94 | public function addComment(CommentEntity $commentEntity): static 95 | { 96 | $this->comments->addItems($commentEntity); 97 | 98 | return $this; 99 | } 100 | 101 | /** 102 | * @throws Throwable 103 | */ 104 | public function deleteComment(CommentEntity $comment): static 105 | { 106 | $this->comments->deleteItems($comment); 107 | 108 | return $this; 109 | } 110 | 111 | /** 112 | * @throws Throwable 113 | */ 114 | public function updateComment(CommentEntity $comment): static 115 | { 116 | $this->comments->updateItems($comment); 117 | 118 | return $this; 119 | } 120 | 121 | /** 122 | * @return CommentEntity[] 123 | */ 124 | public function getComments(): array 125 | { 126 | return $this->comments->getItems(); 127 | } 128 | 129 | /** 130 | * @throws Exception 131 | */ 132 | public function findComment(mixed $key): CommentEntity 133 | { 134 | return $this->comments->findItem($key); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/Blog/Domain/Entity/CommentEntity.php: -------------------------------------------------------------------------------- 1 | getId()?->getValue(); 16 | } 17 | 18 | public function getId(): CommentId 19 | { 20 | return $this->id; 21 | } 22 | 23 | public function setId(CommentId $id): void 24 | { 25 | $this->id = $id; 26 | } 27 | 28 | public function getContent(): CommentContent 29 | { 30 | return $this->content; 31 | } 32 | 33 | public function setContent(CommentContent $content): void 34 | { 35 | $this->content = $content; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Blog/Domain/ValueObject/CommentContent.php: -------------------------------------------------------------------------------- 1 | $comments 24 | * @property-read int|null $comments_count 25 | * @method static Builder|Post newModelQuery() 26 | * @method static Builder|Post newQuery() 27 | * @method static Builder|Post onlyTrashed() 28 | * @method static Builder|Post query() 29 | * @method static Builder|Post whereContent($value) 30 | * @method static Builder|Post whereCreatedAt($value) 31 | * @method static Builder|Post whereDeletedAt($value) 32 | * @method static Builder|Post whereId($value) 33 | * @method static Builder|Post whereSlug($value) 34 | * @method static Builder|Post whereTitle($value) 35 | * @method static Builder|Post whereUpdatedAt($value) 36 | * @method static Builder|Post withTrashed() 37 | * @method static Builder|Post withoutTrashed() 38 | * @mixin Eloquent 39 | */ 40 | class Post extends Model 41 | { 42 | use SoftDeletes; 43 | 44 | protected $table = 'blog_posts'; 45 | protected $casts = []; 46 | 47 | public function comments(): HasMany 48 | { 49 | return $this->hasMany(Comment::class, 'post_id', 'id'); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Blog/Infrastructure/Repository/Mysql/PostQueryRepository.php: -------------------------------------------------------------------------------- 1 | getQuery()->findOrFail($postId); 23 | $postAggregate = $this->toAggregate($post); 24 | 25 | return $postAggregate; 26 | } 27 | 28 | /** 29 | * TODO: separate connection for read only query. 30 | * @return Post|Builder 31 | */ 32 | private function getQuery(): Post|Builder 33 | { 34 | return Post::query(); 35 | } 36 | 37 | /** 38 | * @param Post $post 39 | * @return PostAggregate 40 | * @throws Throwable 41 | */ 42 | private function toAggregate(Post $post): PostAggregate 43 | { 44 | $postAggregate = new PostAggregate( 45 | new PostId($post->id), 46 | new PostSlug($post->slug), 47 | new PostTitle($post->title), 48 | new PostContent($post->content) 49 | ); 50 | 51 | foreach ($post->comments as $comment) { 52 | $postAggregate->addComment(new CommentEntity( 53 | new CommentId($comment->id), 54 | new CommentContent($comment->content) 55 | )); 56 | } 57 | 58 | return $postAggregate; 59 | } 60 | 61 | public function isSlugExists(?string $slug, ?int $ignoreId = null): bool 62 | { 63 | return $this->getQuery()->whereSlug($slug)->whereNot('id', $ignoreId)->exists(); 64 | } 65 | 66 | public function get(): array 67 | { 68 | $posts = $this->getQuery()->all(); 69 | 70 | return $posts->map(fn(Post $post) => $this->toAggregate($post)); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Blog/Infrastructure/Repository/Mysql/PostWriteRepository.php: -------------------------------------------------------------------------------- 1 | getKey()) { 18 | $post = Post::findOrFail($postAggregate->getKey()); 19 | } 20 | 21 | $post->title = $postAggregate->getTitle()->getValue(); 22 | $post->slug = $postAggregate->getSlug()->getValue(); 23 | $post->content = $postAggregate->getContent()->getValue(); 24 | $post->save(); 25 | 26 | $this->updateComments($post, $postAggregate->getComments()); 27 | 28 | return $post->id; 29 | } 30 | 31 | /** 32 | * @param Post $post 33 | * @param CommentEntity[] $commentEntities 34 | * @return void 35 | */ 36 | private function updateComments(Post $post, array $commentEntities): void 37 | { 38 | $validCommentIds = array_map(fn(HasKeyInterface $item) => $item->getKey(), $commentEntities); 39 | $post->comments()->whereNotIn('id', $validCommentIds)->delete(); 40 | 41 | // TODO: can bulk insert and update only changed records 42 | foreach ($commentEntities as $commentEntity) { 43 | $comment = new Comment(); 44 | if ($commentEntity->getKey()) { 45 | $comment = Comment::findOrFail($commentEntity->getKey()); 46 | } 47 | 48 | $comment->post_id = $post->getKey(); 49 | $comment->content = $commentEntity->getContent()->getValue(); 50 | $comment->save(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Blog/Presentation/Api/PostController.php: -------------------------------------------------------------------------------- 1 | bus->dispatch(new CreatePostPayload( 28 | $request->get('title'), 29 | $request->get('slug'), 30 | $request->get('content') 31 | ) 32 | ); 33 | 34 | return response()->json(['data' => ['id' => $postId]]); 35 | } 36 | 37 | /** 38 | * @throws Throwable 39 | */ 40 | public function update(Request $request, int $postId): JsonResponse 41 | { 42 | $postId = $this->bus->dispatch(new UpdatePostPayload( 43 | $postId, 44 | $request->get('title'), 45 | $request->get('slug'), 46 | $request->get('content') 47 | ) 48 | ); 49 | 50 | return response()->json(['data' => ['id' => $postId]]); 51 | } 52 | 53 | public function show(Request $request): JsonResponse 54 | { 55 | $post = $this->bus->dispatch(new FindPostPayload($request->get('id'))); 56 | 57 | return response()->json(['data' => PostViewModel::fromAggregate($post)]); 58 | } 59 | 60 | public function index(Request $request): JsonResponse 61 | { 62 | $posts = $this->bus->dispatch(new GetPostsPayload()); 63 | 64 | return response()->json(['data' => ['posts' => array_map(fn($post) => PostViewModel::fromAggregate($post), $posts)]]); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Blog/Presentation/Api/ViewModel/CommentViewModel.php: -------------------------------------------------------------------------------- 1 | getKey(), $comment->getContent()->getValue()); 19 | } 20 | 21 | public function toArray(): array 22 | { 23 | return [ 24 | 'id' => $this->id, 25 | 'content' => $this->content, 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Blog/Presentation/Api/ViewModel/PostViewModel.php: -------------------------------------------------------------------------------- 1 | getId()->getValue(), 22 | $postAggregate->getTitle()->getValue(), 23 | $postAggregate->getContent()->getValue(), 24 | array_map(fn($comment) => CommentViewModel::fromEntity($comment), $postAggregate->getComments()) 25 | ); 26 | } 27 | 28 | public function toArray(): array 29 | { 30 | return [ 31 | 'id' => $this->id, 32 | 'title' => $this->title, 33 | 'content' => $this->content, 34 | 'comments' => $this->comments, 35 | ]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Blog/Presentation/Cli/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoinv/laravel-clean-ddd/cb3c0444d5bc497671434638198c8934b85a1a31/src/Blog/Presentation/Cli/.gitignore -------------------------------------------------------------------------------- /src/Blog/Presentation/Http/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/khoinv/laravel-clean-ddd/cb3c0444d5bc497671434638198c8934b85a1a31/src/Blog/Presentation/Http/.gitignore -------------------------------------------------------------------------------- /src/Shared/Application/CommandBusInterface.php: -------------------------------------------------------------------------------- 1 | value) && is_int($min) && $this->value < $min, new NumberOverMinException(min: $min)); 19 | ExceptionUtil::throw_if(is_int($this->value) && is_int($max) && $this->value > $max, new NumberOverMaxException(max: $max)); 20 | } 21 | 22 | public function getValue(): ?int 23 | { 24 | return $this->value; 25 | } 26 | 27 | public function setValue(?string $value): void 28 | { 29 | $this->value = $value; 30 | } 31 | 32 | public function getMin(): ?int 33 | { 34 | return $this->min; 35 | } 36 | 37 | public function getMax(): ?int 38 | { 39 | return $this->max; 40 | } 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/Shared/Domain/ValueObject/KeyValueCollection.php: -------------------------------------------------------------------------------- 1 | getKey())) { 28 | $this->_newItems[] = $item; 29 | } else { 30 | $this->_items[$item->getKey()] = $item; 31 | } 32 | 33 | return $this; 34 | } 35 | 36 | /** 37 | * @throws Throwable 38 | */ 39 | public function updateItems(HasKeyInterface $item): static 40 | { 41 | ExceptionUtil::throw_if(is_null($item->getKey()), new Exception("cannot update item without id")); 42 | $this->_items[$item->getKey()] = $item; 43 | 44 | return $this; 45 | } 46 | 47 | 48 | /** 49 | * @throws Throwable 50 | */ 51 | public function deleteItems(HasKeyInterface $item): static 52 | { 53 | ExceptionUtil::throw_if(is_null($item->getKey()), new Exception("cannot delete item without id")); 54 | unset($this->_items[$item->getKey()]); 55 | 56 | return $this; 57 | } 58 | 59 | /** 60 | * @return T[] 61 | */ 62 | public function getItems(): array 63 | { 64 | return array_merge($this->_items, $this->_newItems); 65 | } 66 | 67 | /** 68 | * @param mixed $key 69 | * @return T 70 | * @throws Exception 71 | */ 72 | public function findItem(mixed $key) 73 | { 74 | if (key_exists($key, $this->_items)) { 75 | return $this->_items[$key]; 76 | } 77 | 78 | throw new Exception("Item not found"); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/Shared/Domain/ValueObject/StringValue.php: -------------------------------------------------------------------------------- 1 | value) && is_int($limit) && strlen($this->value) > $limit, new StringToLongException(limit: $limit)); 18 | } 19 | 20 | public function getValue(): ?string 21 | { 22 | return $this->value; 23 | } 24 | 25 | public function setValue(?string $value): void 26 | { 27 | $this->value = $value; 28 | } 29 | 30 | public function getLimit(): ?int 31 | { 32 | return $this->limit; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Shared/Exception/DomainException.php: -------------------------------------------------------------------------------- 1 | message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Shared/Exception/ValueObject/NumberOverMinException.php: -------------------------------------------------------------------------------- 1 | message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Shared/Exception/ValueObject/StringToLongException.php: -------------------------------------------------------------------------------- 1 | message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Shared/Infrastructure/CommandBus.php: -------------------------------------------------------------------------------- 1 | bus->dispatch($command); 15 | } 16 | 17 | public function map(array $map): Dispatcher 18 | { 19 | return $this->bus->map($map); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Shared/SharedProvider.php: -------------------------------------------------------------------------------- 1 | app->singleton(CommandBusInterface::class, CommandBus::class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Shared/Slug.php: -------------------------------------------------------------------------------- 1 | make(CommandBusInterface::class); 21 | 22 | $postId = $bus->dispatch(new CreatePostPayload( 23 | title: 'a-title ' . time() . rand(1, 10000000), 24 | slug: null, 25 | content: 'A content' 26 | )); 27 | 28 | $bus->dispatch( 29 | new CreateCommentPayload( 30 | $postId, 31 | "Just a comment 1" 32 | ) 33 | ); 34 | 35 | $bus->dispatch( 36 | new CreateCommentPayload( 37 | $postId, 38 | "Just a comment 2" 39 | ) 40 | ); 41 | 42 | // TODO: add assert 43 | $this->assertTrue(true); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 16 | 17 | $response->assertStatus(200); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import laravel from 'laravel-vite-plugin'; 3 | 4 | export default defineConfig({ 5 | plugins: [ 6 | laravel({ 7 | input: ['resources/css/app.css', 'resources/js/app.js'], 8 | refresh: true, 9 | }), 10 | ], 11 | }); 12 | --------------------------------------------------------------------------------