├── public ├── favicon.ico ├── robots.txt ├── index.php └── .htaccess ├── database ├── .gitignore ├── seeders │ └── DatabaseSeeder.php ├── migrations │ ├── 2024_02_20_000002_add_soft_deletes_to_clientes_table.php │ ├── 2024_02_20_000000_create_empresas_table.php │ ├── 2024_02_20_000001_create_clientes_table.php │ ├── 2025_04_24_004125_add_empresa_id_to_clientes_table.php │ ├── 0001_01_01_000001_create_cache_table.php │ ├── 0001_01_01_000000_create_users_table.php │ └── 0001_01_01_000002_create_jobs_table.php └── factories │ └── UserFactory.php ├── bootstrap ├── cache │ └── .gitignore ├── providers.php └── app.php ├── resources ├── js │ ├── app.js │ └── bootstrap.js ├── css │ └── app.css └── views │ └── welcome.blade.php ├── storage ├── logs │ └── .gitignore ├── app │ ├── private │ │ └── .gitignore │ ├── public │ │ └── .gitignore │ └── .gitignore └── framework │ ├── testing │ └── .gitignore │ ├── views │ └── .gitignore │ ├── cache │ ├── data │ │ └── .gitignore │ └── .gitignore │ ├── sessions │ └── .gitignore │ └── .gitignore ├── routes ├── web.php ├── console.php └── api.php ├── tests ├── TestCase.php ├── Unit │ └── ExampleTest.php └── Feature │ ├── ExampleTest.php │ ├── EmpresaTest.php │ └── ClienteTest.php ├── .gitattributes ├── Dockerfile ├── .editorconfig ├── app ├── Application │ ├── DTOs │ │ └── Cliente │ │ │ └── CreateClienteDTO.php │ └── UseCases │ │ └── Clientes │ │ └── CreateClienteUseCase.php ├── Interfaces │ └── Http │ │ ├── Controllers │ │ ├── Controller.php │ │ └── ClienteController.php │ │ ├── Requests │ │ └── ClienteRequest.php │ │ └── Resources │ │ └── ClienteResource.php ├── Http │ └── Controllers │ │ ├── Controller.php │ │ ├── ClienteController.php │ │ └── EmpresaController.php ├── Domain │ └── Empresa │ │ ├── Models │ │ └── Empresa.php │ │ ├── Repositories │ │ └── EmpresaRepositoryInterface.php │ │ ├── Services │ │ └── EmpresaService.php │ │ └── DTO │ │ ├── CriarEmpresaDTO.php │ │ └── EmpresaListagemDTO.php ├── Providers │ ├── BroadcastServiceProvider.php │ ├── AuthServiceProvider.php │ ├── EventServiceProvider.php │ ├── AppServiceProvider.php │ └── RouteServiceProvider.php ├── Dominios │ └── Clientes │ │ ├── Services │ │ └── ClienteService.php │ │ ├── Models │ │ └── Cliente.php │ │ ├── Interfaces │ │ └── ClienteRepositoryInterface.php │ │ ├── DTO │ │ ├── ClienteListagemDTO.php │ │ └── AtualizarClienteDTO.php │ │ └── Repositories │ │ └── ClienteRepository.php ├── Domains │ └── Clientes │ │ ├── Models │ │ └── Cliente.php │ │ ├── Dtos │ │ └── CriarClienteDto.php │ │ ├── Services │ │ └── ClienteService.php │ │ └── Repositories │ │ └── ClienteRepository.php └── Infra │ └── Empresa │ └── Repositories │ └── EmpresaRepositoryEloquent.php ├── .gitignore ├── vite.config.js ├── package.json ├── artisan ├── nginx └── conf.d │ └── default.conf ├── docker-compose.yml ├── config ├── services.php ├── filesystems.php ├── cache.php ├── mail.php ├── queue.php ├── auth.php ├── logging.php ├── database.php ├── app.php └── session.php ├── phpunit.xml ├── .env.example ├── composer.json └── README.md /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite* 2 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /resources/js/app.js: -------------------------------------------------------------------------------- 1 | import './bootstrap'; 2 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /storage/app/private/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !private/ 3 | !public/ 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /bootstrap/providers.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 8 | })->purpose('Display an inspiring quote'); 9 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM php:8.3-fpm 2 | 3 | WORKDIR /var/www 4 | 5 | RUN apt-get update && apt-get install -y \ 6 | git zip unzip curl libpng-dev libonig-dev libxml2-dev libzip-dev \ 7 | && docker-php-ext-install pdo_mysql mbstring zip exif pcntl 8 | 9 | COPY --from=composer:latest /usr/bin/composer /usr/bin/composer 10 | -------------------------------------------------------------------------------- /tests/Unit/ExampleTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /app/Application/DTOs/Cliente/CreateClienteDTO.php: -------------------------------------------------------------------------------- 1 | get('/'); 16 | 17 | $response->assertStatus(200); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | repository->remover($id); 17 | } 18 | } -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | handleCommand(new ArgvInput); 17 | 18 | exit($status); 19 | -------------------------------------------------------------------------------- /app/Dominios/Clientes/Models/Cliente.php: -------------------------------------------------------------------------------- 1 | create(); 17 | 18 | User::factory()->create([ 19 | 'name' => 'Test User', 20 | 'email' => 'test@example.com', 21 | ]); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Domains/Clientes/Models/Cliente.php: -------------------------------------------------------------------------------- 1 | 'datetime', 22 | 'updated_at' => 'datetime', 23 | 'deleted_at' => 'datetime' 24 | ]; 25 | } -------------------------------------------------------------------------------- /app/Domain/Empresa/Repositories/EmpresaRepositoryInterface.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 | -------------------------------------------------------------------------------- /nginx/conf.d/default.conf: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | index index.php index.html; 4 | server_name localhost; 5 | 6 | root /var/www/public; 7 | 8 | location / { 9 | try_files $uri $uri/ /index.php?$query_string; 10 | } 11 | 12 | location ~ \.php$ { 13 | include fastcgi_params; 14 | fastcgi_pass app:9000; 15 | fastcgi_index index.php; 16 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 17 | fastcgi_param PATH_INFO $fastcgi_path_info; 18 | } 19 | 20 | location ~ /\.ht { 21 | deny all; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | handleRequest(Request::capture()); 21 | -------------------------------------------------------------------------------- /database/migrations/2024_02_20_000002_add_soft_deletes_to_clientes_table.php: -------------------------------------------------------------------------------- 1 | softDeletes(); 13 | }); 14 | } 15 | 16 | public function down(): void 17 | { 18 | Schema::table('clientes', function (Blueprint $table) { 19 | $table->dropSoftDeletes(); 20 | }); 21 | } 22 | }; -------------------------------------------------------------------------------- /app/Dominios/Clientes/Interfaces/ClienteRepositoryInterface.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | protected $policies = [ 16 | // 17 | ]; 18 | 19 | /** 20 | * Register any authentication / authorization services. 21 | */ 22 | public function boot(): void 23 | { 24 | $this->registerPolicies(); 25 | 26 | // 27 | } 28 | } -------------------------------------------------------------------------------- /app/Interfaces/Http/Requests/ClienteRequest.php: -------------------------------------------------------------------------------- 1 | 'required|string|max:255', 18 | 'email' => 'required|email|unique:clientes,email', 19 | 'telefone' => 'required|string', 20 | 'cpf' => 'required|string|size:11|unique:clientes,cpf', 21 | 'empresa_id' => 'required|exists:empresas,id' 22 | ]; 23 | } 24 | } -------------------------------------------------------------------------------- /app/Application/UseCases/Clientes/CreateClienteUseCase.php: -------------------------------------------------------------------------------- 1 | service->criarCliente([ 18 | 'nome' => $dto->nome, 19 | 'email' => $dto->email, 20 | 'telefone' => $dto->telefone, 21 | 'cpf' => $dto->cpf, 22 | 'empresa_id' => $dto->empresa_id 23 | ]); 24 | } 25 | } -------------------------------------------------------------------------------- /app/Interfaces/Http/Resources/ClienteResource.php: -------------------------------------------------------------------------------- 1 | $this->id, 19 | 'nome' => $this->nome, 20 | 'email' => $this->email, 21 | 'telefone' => $this->telefone, 22 | 'cpf' => $this->cpf, 23 | 'created_at' => $this->created_at, 24 | 'updated_at' => $this->updated_at 25 | ]; 26 | } 27 | } -------------------------------------------------------------------------------- /database/migrations/2024_02_20_000000_create_empresas_table.php: -------------------------------------------------------------------------------- 1 | id(); 13 | $table->string('nome'); 14 | $table->string('cnpj', 14)->unique(); 15 | $table->string('email')->nullable(); 16 | $table->string('telefone')->nullable(); 17 | $table->timestamps(); 18 | $table->softDeletes(); 19 | }); 20 | } 21 | 22 | public function down(): void 23 | { 24 | Schema::dropIfExists('empresas'); 25 | } 26 | }; -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | group(function () { 14 | Route::post('/empresas', 'store'); 15 | Route::get('/empresas', 'index'); 16 | Route::delete('/empresas/{id}', 'destroy'); 17 | }); 18 | 19 | -------------------------------------------------------------------------------- /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 | # Handle X-XSRF-Token Header 13 | RewriteCond %{HTTP:x-xsrf-token} . 14 | RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}] 15 | 16 | # Redirect Trailing Slashes If Not A Folder... 17 | RewriteCond %{REQUEST_FILENAME} !-d 18 | RewriteCond %{REQUEST_URI} (.+)/$ 19 | RewriteRule ^ %1 [L,R=301] 20 | 21 | # Send Requests To Front Controller... 22 | RewriteCond %{REQUEST_FILENAME} !-d 23 | RewriteCond %{REQUEST_FILENAME} !-f 24 | RewriteRule ^ index.php [L] 25 | 26 | -------------------------------------------------------------------------------- /app/Domain/Empresa/Services/EmpresaService.php: -------------------------------------------------------------------------------- 1 | repository->criar($dados); 19 | } 20 | 21 | public function listar(): LengthAwarePaginator 22 | { 23 | return $this->repository->listar(); 24 | } 25 | 26 | public function excluir(int $id): void 27 | { 28 | $this->repository->excluir($id); 29 | } 30 | } -------------------------------------------------------------------------------- /database/migrations/2024_02_20_000001_create_clientes_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('nome'); 17 | $table->string('email')->unique(); 18 | $table->string('telefone')->nullable(); 19 | $table->string('cpf')->unique(); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | */ 27 | public function down(): void 28 | { 29 | Schema::dropIfExists('clientes'); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /app/Http/Controllers/ClienteController.php: -------------------------------------------------------------------------------- 1 | validate([ 19 | 'nome' => 'required|string', 20 | 'email' => 'nullable|email', 21 | 'telefone' => 'nullable' 22 | ]); 23 | 24 | $dto = CriarClienteDto::fromArray($validated); 25 | $cliente = $this->createClienteUseCase->execute($dto); 26 | 27 | return response()->json($cliente, 201); 28 | } 29 | } -------------------------------------------------------------------------------- /app/Domain/Empresa/DTO/CriarEmpresaDTO.php: -------------------------------------------------------------------------------- 1 | $this->nome, 28 | 'cnpj' => $this->cnpj, 29 | 'email' => $this->email, 30 | 'telefone' => $this->telefone 31 | ]; 32 | } 33 | } -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | app: 3 | build: 4 | context: . 5 | dockerfile: Dockerfile 6 | container_name: mini_crm_app 7 | volumes: 8 | - .:/var/www 9 | ports: 10 | - "9000:9000" 11 | depends_on: 12 | - db 13 | 14 | nginx: 15 | image: nginx:latest 16 | container_name: mini_crm_nginx 17 | ports: 18 | - "${APP_PORT:-8080}:80" 19 | volumes: 20 | - .:/var/www 21 | - ./nginx/conf.d:/etc/nginx/conf.d 22 | depends_on: 23 | - app 24 | 25 | db: 26 | image: mysql:8.0 27 | container_name: mini_crm_db 28 | restart: unless-stopped 29 | environment: 30 | MYSQL_ROOT_PASSWORD: ${DB_PASSWORD} 31 | MYSQL_DATABASE: ${DB_DATABASE} 32 | MYSQL_USER: ${DB_USERNAME} 33 | MYSQL_PASSWORD: ${DB_PASSWORD} 34 | ports: 35 | - "3306:3306" 36 | volumes: 37 | - dbdata:/var/lib/mysql 38 | 39 | volumes: 40 | dbdata: 41 | -------------------------------------------------------------------------------- /database/migrations/2025_04_24_004125_add_empresa_id_to_clientes_table.php: -------------------------------------------------------------------------------- 1 | unsignedBigInteger('empresa_id'); 16 | 17 | $table->foreign('empresa_id') 18 | ->references('id') 19 | ->on('empresas') 20 | ->onDelete('cascade'); 21 | }); 22 | } 23 | 24 | public function down(): void 25 | { 26 | Schema::table('clientes', function (Blueprint $table) { 27 | $table->dropForeign(['empresa_id']); 28 | $table->dropColumn('empresa_id'); 29 | }); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /app/Domain/Empresa/DTO/EmpresaListagemDTO.php: -------------------------------------------------------------------------------- 1 | id, 23 | nome: $empresa->nome, 24 | cnpj: $empresa->cnpj, 25 | email: $empresa->email, 26 | telefone: $empresa->telefone, 27 | created_at: $empresa->created_at->toDateTimeString(), 28 | updated_at: $empresa->updated_at->toDateTimeString() 29 | ); 30 | } 31 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/Providers/EventServiceProvider.php: -------------------------------------------------------------------------------- 1 | > 16 | */ 17 | protected $listen = [ 18 | Registered::class => [ 19 | SendEmailVerificationNotification::class, 20 | ], 21 | ]; 22 | 23 | /** 24 | * Register any events for your application. 25 | */ 26 | public function boot(): void 27 | { 28 | // 29 | } 30 | 31 | /** 32 | * Determine if events and listeners should be automatically discovered. 33 | */ 34 | public function shouldDiscoverEvents(): bool 35 | { 36 | return false; 37 | } 38 | } -------------------------------------------------------------------------------- /app/Dominios/Clientes/DTO/ClienteListagemDTO.php: -------------------------------------------------------------------------------- 1 | id, 24 | nome: $cliente->nome, 25 | email: $cliente->email, 26 | telefone: $cliente->telefone, 27 | cpf: $cliente->cpf, 28 | empresa_id: $cliente->empresa_id, 29 | created_at: $cliente->created_at->toDateTimeString(), 30 | updated_at: $cliente->updated_at->toDateTimeString() 31 | ); 32 | } 33 | } -------------------------------------------------------------------------------- /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 | 'resend' => [ 28 | 'key' => env('RESEND_KEY'), 29 | ], 30 | 31 | 'slack' => [ 32 | 'notifications' => [ 33 | 'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'), 34 | 'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'), 35 | ], 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->bind(EmpresaRepositoryInterface::class, EmpresaRepositoryEloquent::class); 20 | 21 | $this->app->bind(ClienteRepository::class, function ($app) { 22 | return new ClienteRepository($app->make(Cliente::class)); 23 | }); 24 | 25 | $this->app->bind(ClienteService::class, function ($app) { 26 | return new ClienteService($app->make(ClienteRepository::class)); 27 | }); 28 | } 29 | 30 | /** 31 | * Bootstrap any application services. 32 | */ 33 | public function boot(): void 34 | { 35 | // 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Domains/Clientes/Services/ClienteService.php: -------------------------------------------------------------------------------- 1 | repository = $repository; 15 | } 16 | 17 | public function criarCliente(array $data) 18 | { 19 | // Verificar se CPF já existe 20 | $clienteExistente = $this->repository->findByCpf($data['cpf']); 21 | if ($clienteExistente) { 22 | throw ValidationException::withMessages([ 23 | 'cpf' => ['CPF já cadastrado'] 24 | ]); 25 | } 26 | 27 | return $this->repository->create($data); 28 | } 29 | 30 | public function atualizarCliente(int $id, array $data) 31 | { 32 | return $this->repository->update($id, $data); 33 | } 34 | 35 | public function buscarCliente(int $id) 36 | { 37 | return $this->repository->find($id); 38 | } 39 | 40 | public function deletarCliente(int $id) 41 | { 42 | return $this->repository->delete($id); 43 | } 44 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | by($request->user()?->id ?: $request->ip()); 29 | }); 30 | 31 | $this->routes(function () { 32 | Route::middleware('api') 33 | ->prefix('api') 34 | ->group(base_path('routes/api.php')); 35 | 36 | Route::middleware('web') 37 | ->group(base_path('routes/web.php')); 38 | }); 39 | } 40 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/Domains/Clientes/Repositories/ClienteRepository.php: -------------------------------------------------------------------------------- 1 | model = $model; 15 | } 16 | 17 | public function find(int $id) 18 | { 19 | return $this->model->find($id); 20 | } 21 | 22 | public function findByCpf(string $cpf) 23 | { 24 | return $this->model->where('cpf', $cpf)->first(); 25 | } 26 | 27 | public function create(array $data) 28 | { 29 | try { 30 | return $this->model->create($data); 31 | } catch (\Exception $e) { 32 | throw new \Exception('Erro ao criar cliente: ' . $e->getMessage()); 33 | } 34 | } 35 | 36 | public function update(int $id, array $data) 37 | { 38 | $cliente = $this->find($id); 39 | if ($cliente) { 40 | $cliente->update($data); 41 | } 42 | return $cliente; 43 | } 44 | 45 | public function delete(int $id) 46 | { 47 | $cliente = $this->find($id); 48 | if ($cliente) { 49 | $cliente->delete(); 50 | } 51 | return $cliente; 52 | } 53 | } -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | APP_PORT=8000 7 | 8 | 9 | APP_LOCALE=en 10 | APP_FALLBACK_LOCALE=en 11 | APP_FAKER_LOCALE=en_US 12 | 13 | APP_MAINTENANCE_DRIVER=file 14 | # APP_MAINTENANCE_STORE=database 15 | 16 | PHP_CLI_SERVER_WORKERS=4 17 | 18 | BCRYPT_ROUNDS=12 19 | 20 | LOG_CHANNEL=stack 21 | LOG_STACK=single 22 | LOG_DEPRECATIONS_CHANNEL=null 23 | LOG_LEVEL=debug 24 | 25 | DB_CONNECTION=mysql 26 | DB_HOST=db 27 | DB_PORT=3306 28 | DB_DATABASE=laravel 29 | DB_USERNAME=laravel 30 | DB_PASSWORD=root 31 | 32 | SESSION_DRIVER=database 33 | SESSION_LIFETIME=120 34 | SESSION_ENCRYPT=false 35 | SESSION_PATH=/ 36 | SESSION_DOMAIN=null 37 | 38 | BROADCAST_CONNECTION=log 39 | FILESYSTEM_DISK=local 40 | QUEUE_CONNECTION=database 41 | 42 | CACHE_STORE=database 43 | # CACHE_PREFIX= 44 | 45 | MEMCACHED_HOST=127.0.0.1 46 | 47 | REDIS_CLIENT=phpredis 48 | REDIS_HOST=127.0.0.1 49 | REDIS_PASSWORD=null 50 | REDIS_PORT=6379 51 | 52 | MAIL_MAILER=log 53 | MAIL_SCHEME=null 54 | MAIL_HOST=127.0.0.1 55 | MAIL_PORT=2525 56 | MAIL_USERNAME=null 57 | MAIL_PASSWORD=null 58 | MAIL_FROM_ADDRESS="hello@example.com" 59 | MAIL_FROM_NAME="${APP_NAME}" 60 | 61 | AWS_ACCESS_KEY_ID= 62 | AWS_SECRET_ACCESS_KEY= 63 | AWS_DEFAULT_REGION=us-east-1 64 | AWS_BUCKET= 65 | AWS_USE_PATH_STYLE_ENDPOINT=false 66 | 67 | VITE_APP_NAME="${APP_NAME}" 68 | -------------------------------------------------------------------------------- /app/Dominios/Clientes/DTO/AtualizarClienteDTO.php: -------------------------------------------------------------------------------- 1 | 'required|string|min:3|max:255', 21 | 'email' => 'required|email|max:255', 22 | 'cpf' => 'required|string|size:14', 23 | 'telefone' => 'required|string|min:14|max:15' 24 | ]); 25 | 26 | if ($validator->fails()) { 27 | throw new ValidationException($validator); 28 | } 29 | 30 | return new self( 31 | nome: $data['nome'], 32 | email: $data['email'], 33 | cpf: $data['cpf'], 34 | telefone: $data['telefone'] 35 | ); 36 | } 37 | 38 | public function toArray(): array 39 | { 40 | return [ 41 | 'nome' => $this->nome, 42 | 'email' => $this->email, 43 | 'cpf' => $this->cpf, 44 | 'telefone' => $this->telefone 45 | ]; 46 | } 47 | } -------------------------------------------------------------------------------- /app/Infra/Empresa/Repositories/EmpresaRepositoryEloquent.php: -------------------------------------------------------------------------------- 1 | model->create([ 21 | 'nome' => $dados->nome, 22 | 'cnpj' => $dados->cnpj, 23 | 'email' => $dados->email, 24 | 'telefone' => $dados->telefone 25 | ]); 26 | } 27 | 28 | public function listar(): LengthAwarePaginator 29 | { 30 | return $this->model->paginate(10); 31 | } 32 | 33 | public function encontrarPorId(int $id): ?Empresa 34 | { 35 | return $this->model->find($id); 36 | } 37 | 38 | public function excluir(int $id): void 39 | { 40 | $empresa = $this->model->find($id); 41 | 42 | if (!$empresa) { 43 | throw new ModelNotFoundException("Empresa não encontrada"); 44 | } 45 | 46 | $empresa->delete(); 47 | } 48 | } -------------------------------------------------------------------------------- /tests/Feature/EmpresaTest.php: -------------------------------------------------------------------------------- 1 | 'Empresa Teste', 17 | 'cnpj' => '12345678000199', 18 | 'email' => 'empresa@teste.com', 19 | 'telefone' => '11999999999' 20 | ]; 21 | 22 | $response = $this->postJson('/api/empresas', $dados); 23 | 24 | $response->assertStatus(201) 25 | ->assertJsonStructure([ 26 | 'data' => [ 27 | 'id', 28 | 'nome', 29 | 'cnpj', 30 | 'email', 31 | 'telefone', 32 | 'created_at', 33 | 'updated_at' 34 | ], 35 | 'message' 36 | ]) 37 | ->assertJson([ 38 | 'data' => [ 39 | 'nome' => $dados['nome'], 40 | 'cnpj' => $dados['cnpj'], 41 | 'email' => $dados['email'], 42 | 'telefone' => $dados['telefone'] 43 | ], 44 | 'message' => 'Empresa criada com sucesso' 45 | ]); 46 | 47 | $this->assertDatabaseHas('empresas', [ 48 | 'nome' => $dados['nome'], 49 | 'cnpj' => $dados['cnpj'] 50 | ]); 51 | } 52 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/Dominios/Clientes/Repositories/ClienteRepository.php: -------------------------------------------------------------------------------- 1 | model->create($dados); 21 | } 22 | 23 | public function todos(): Collection 24 | { 25 | return $this->model->all(); 26 | } 27 | 28 | public function paginados(int $perPage = 15): LengthAwarePaginator 29 | { 30 | return $this->model->paginate($perPage); 31 | } 32 | 33 | public function atualizar(int $id, AtualizarClienteDTO $dto): Cliente 34 | { 35 | $cliente = $this->model->find($id); 36 | 37 | if (!$cliente) { 38 | throw new ModelNotFoundException("Cliente não encontrado"); 39 | } 40 | 41 | $cliente->update($dto->toArray()); 42 | 43 | return $cliente; 44 | } 45 | 46 | public function remover(int $id): void 47 | { 48 | $cliente = $this->model->find($id); 49 | 50 | if (!$cliente) { 51 | throw new ModelNotFoundException("Cliente não encontrado"); 52 | } 53 | 54 | $cliente->delete(); 55 | } 56 | 57 | public function todosComExcluidos(): Collection 58 | { 59 | return $this->model->withTrashed()->get(); 60 | } 61 | 62 | public function apenasExcluidos(): Collection 63 | { 64 | return $this->model->onlyTrashed()->get(); 65 | } 66 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://getcomposer.org/schema.json", 3 | "name": "laravel/laravel", 4 | "type": "project", 5 | "description": "The skeleton application for the Laravel framework.", 6 | "keywords": ["laravel", "framework"], 7 | "license": "MIT", 8 | "require": { 9 | "php": "^8.2", 10 | "laravel/framework": "^12.0", 11 | "laravel/tinker": "^2.10.1" 12 | }, 13 | "require-dev": { 14 | "fakerphp/faker": "^1.23", 15 | "laravel/pail": "^1.2.2", 16 | "laravel/pint": "^1.13", 17 | "laravel/sail": "^1.41", 18 | "mockery/mockery": "^1.6", 19 | "nunomaduro/collision": "^8.6", 20 | "phpunit/phpunit": "^11.5.3" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "App\\": "app/", 25 | "Database\\Factories\\": "database/factories/", 26 | "Database\\Seeders\\": "database/seeders/" 27 | } 28 | }, 29 | "autoload-dev": { 30 | "psr-4": { 31 | "Tests\\": "tests/" 32 | } 33 | }, 34 | "scripts": { 35 | "post-autoload-dump": [ 36 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 37 | "@php artisan package:discover --ansi" 38 | ], 39 | "post-update-cmd": [ 40 | "@php artisan vendor:publish --tag=laravel-assets --ansi --force" 41 | ], 42 | "post-root-package-install": [ 43 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 44 | ], 45 | "post-create-project-cmd": [ 46 | "@php artisan key:generate --ansi", 47 | "@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"", 48 | "@php artisan migrate --graceful --ansi" 49 | ], 50 | "dev": [ 51 | "Composer\\Config::disableProcessTimeout", 52 | "npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite" 53 | ], 54 | "test": [ 55 | "@php artisan config:clear --ansi", 56 | "@php artisan test" 57 | ] 58 | }, 59 | "extra": { 60 | "laravel": { 61 | "dont-discover": [] 62 | } 63 | }, 64 | "config": { 65 | "optimize-autoloader": true, 66 | "preferred-install": "dist", 67 | "sort-packages": true, 68 | "allow-plugins": { 69 | "pestphp/pest-plugin": true, 70 | "php-http/discovery": true 71 | } 72 | }, 73 | "minimum-stability": "stable", 74 | "prefer-stable": true 75 | } 76 | -------------------------------------------------------------------------------- /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/private'), 36 | 'serve' => true, 37 | 'throw' => false, 38 | 'report' => false, 39 | ], 40 | 41 | 'public' => [ 42 | 'driver' => 'local', 43 | 'root' => storage_path('app/public'), 44 | 'url' => env('APP_URL').'/storage', 45 | 'visibility' => 'public', 46 | 'throw' => false, 47 | 'report' => false, 48 | ], 49 | 50 | 's3' => [ 51 | 'driver' => 's3', 52 | 'key' => env('AWS_ACCESS_KEY_ID'), 53 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 54 | 'region' => env('AWS_DEFAULT_REGION'), 55 | 'bucket' => env('AWS_BUCKET'), 56 | 'url' => env('AWS_URL'), 57 | 'endpoint' => env('AWS_ENDPOINT'), 58 | 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 59 | 'throw' => false, 60 | 'report' => false, 61 | ], 62 | 63 | ], 64 | 65 | /* 66 | |-------------------------------------------------------------------------- 67 | | Symbolic Links 68 | |-------------------------------------------------------------------------- 69 | | 70 | | Here you may configure the symbolic links that will be created when the 71 | | `storage:link` Artisan command is executed. The array keys should be 72 | | the locations of the links and the values should be their targets. 73 | | 74 | */ 75 | 76 | 'links' => [ 77 | public_path('storage') => storage_path('app/public'), 78 | ], 79 | 80 | ]; 81 | -------------------------------------------------------------------------------- /app/Http/Controllers/EmpresaController.php: -------------------------------------------------------------------------------- 1 | service->listar(); 21 | 22 | $empresas->getCollection()->transform(function ($empresa) { 23 | return EmpresaListagemDTO::fromModel($empresa); 24 | }); 25 | 26 | return response()->json($empresas); 27 | } 28 | 29 | public function store(Request $request): JsonResponse 30 | { 31 | try { 32 | $dados = $request->validate([ 33 | 'nome' => 'required|string|min:3|max:255', 34 | 'cnpj' => 'required|string|size:14', 35 | 'email' => 'nullable|email|max:255', 36 | 'telefone' => 'nullable|string|min:10|max:11' 37 | ]); 38 | 39 | $dto = CriarEmpresaDTO::fromArray($dados); 40 | $empresa = $this->service->criar($dto); 41 | 42 | return response()->json([ 43 | 'data' => [ 44 | 'id' => $empresa->id, 45 | 'nome' => $empresa->nome, 46 | 'cnpj' => $empresa->cnpj, 47 | 'email' => $empresa->email, 48 | 'telefone' => $empresa->telefone, 49 | 'created_at' => $empresa->created_at, 50 | 'updated_at' => $empresa->updated_at 51 | ], 52 | 'message' => 'Empresa criada com sucesso' 53 | ], 201); 54 | } catch (ValidationException $e) { 55 | return response()->json([ 56 | 'message' => 'Dados inválidos', 57 | 'errors' => $e->errors() 58 | ], 422); 59 | } catch (\Exception $e) { 60 | return response()->json([ 61 | 'message' => 'Erro ao criar empresa', 62 | 'error' => $e->getMessage() 63 | ], 500); 64 | } 65 | } 66 | 67 | public function destroy(int $id): JsonResponse 68 | { 69 | try { 70 | $this->service->excluir($id); 71 | 72 | return response()->json([ 73 | 'message' => 'Empresa excluída com sucesso' 74 | ]); 75 | } catch (\Exception $e) { 76 | return response()->json([ 77 | 'message' => 'Erro ao remover empresa' 78 | ], 500); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /tests/Feature/ClienteTest.php: -------------------------------------------------------------------------------- 1 | 'Empresa Teste', 17 | 'cnpj' => '12345678000199', 18 | 'email' => 'empresa@teste.com', 19 | 'telefone' => '11999999999' 20 | ]; 21 | 22 | $empresaResponse = $this->postJson('/api/empresas', $empresaData); 23 | $empresaId = $empresaResponse->json('data.id'); 24 | 25 | $clienteData = [ 26 | 'nome' => 'João da Silva', 27 | 'email' => 'joao@example.com', 28 | 'telefone' => '11999999999', 29 | 'cpf' => '12345678900', 30 | 'empresa_id' => $empresaId 31 | ]; 32 | 33 | $response = $this->postJson('/api/clientes', $clienteData); 34 | 35 | $response->assertStatus(201) 36 | ->assertJsonStructure([ 37 | 'data' => [ 38 | 'id', 39 | 'nome', 40 | 'email', 41 | 'telefone', 42 | 'cpf', 43 | 'empresa_id', 44 | 'created_at', 45 | 'updated_at' 46 | ], 47 | 'message' 48 | ]); 49 | 50 | $this->assertDatabaseHas('clientes', [ 51 | 'nome' => 'João da Silva', 52 | 'email' => 'joao@example.com', 53 | 'cpf' => '12345678900', 54 | 'empresa_id' => $empresaId 55 | ]); 56 | } 57 | 58 | public function test_nao_pode_criar_cliente_com_dados_invalidos() 59 | { 60 | $clienteData = [ 61 | 'nome' => '', 62 | 'email' => 'email-invalido', 63 | 'telefone' => '', 64 | 'cpf' => '123', 65 | 'empresa_id' => 999 // empresa que não existe 66 | ]; 67 | 68 | $response = $this->postJson('/api/clientes', $clienteData); 69 | 70 | $response->assertStatus(422) 71 | ->assertJsonValidationErrors(['nome', 'email', 'telefone', 'cpf', 'empresa_id']); 72 | } 73 | 74 | public function test_nao_pode_criar_cliente_com_cpf_duplicado() 75 | { 76 | // Primeiro, criamos uma empresa 77 | $empresaData = [ 78 | 'nome' => 'Empresa Teste', 79 | 'cnpj' => '12345678000199', 80 | 'email' => 'empresa@teste.com', 81 | 'telefone' => '11999999999' 82 | ]; 83 | 84 | $empresaResponse = $this->postJson('/api/empresas', $empresaData); 85 | $empresaId = $empresaResponse->json('data.id'); 86 | 87 | // Dados do primeiro cliente 88 | $clienteData = [ 89 | 'nome' => 'João da Silva', 90 | 'email' => 'joao@example.com', 91 | 'telefone' => '11999999999', 92 | 'cpf' => '12345678900', 93 | 'empresa_id' => $empresaId 94 | ]; 95 | 96 | // Criamos o primeiro cliente 97 | $this->postJson('/api/clientes', $clienteData); 98 | 99 | // Tentamos criar outro cliente com o mesmo CPF 100 | $clienteData2 = $clienteData; 101 | $clienteData2['email'] = 'outro@email.com'; 102 | 103 | $response = $this->postJson('/api/clientes', $clienteData2); 104 | 105 | $response->assertStatus(422) 106 | ->assertJsonValidationErrors(['cpf']); 107 | } 108 | } -------------------------------------------------------------------------------- /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: "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 | 'connection' => env('DB_CACHE_CONNECTION'), 44 | 'table' => env('DB_CACHE_TABLE', 'cache'), 45 | 'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'), 46 | 'lock_table' => env('DB_CACHE_LOCK_TABLE'), 47 | ], 48 | 49 | 'file' => [ 50 | 'driver' => 'file', 51 | 'path' => storage_path('framework/cache/data'), 52 | 'lock_path' => storage_path('framework/cache/data'), 53 | ], 54 | 55 | 'memcached' => [ 56 | 'driver' => 'memcached', 57 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 58 | 'sasl' => [ 59 | env('MEMCACHED_USERNAME'), 60 | env('MEMCACHED_PASSWORD'), 61 | ], 62 | 'options' => [ 63 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 64 | ], 65 | 'servers' => [ 66 | [ 67 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 68 | 'port' => env('MEMCACHED_PORT', 11211), 69 | 'weight' => 100, 70 | ], 71 | ], 72 | ], 73 | 74 | 'redis' => [ 75 | 'driver' => 'redis', 76 | 'connection' => env('REDIS_CACHE_CONNECTION', 'cache'), 77 | 'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'), 78 | ], 79 | 80 | 'dynamodb' => [ 81 | 'driver' => 'dynamodb', 82 | 'key' => env('AWS_ACCESS_KEY_ID'), 83 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 84 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 85 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 86 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 87 | ], 88 | 89 | 'octane' => [ 90 | 'driver' => 'octane', 91 | ], 92 | 93 | ], 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Cache Key Prefix 98 | |-------------------------------------------------------------------------- 99 | | 100 | | When utilizing the APC, database, memcached, Redis, and DynamoDB cache 101 | | stores, there might be other applications using the same cache. For 102 | | that reason, you may prefix every cache key to avoid collisions. 103 | | 104 | */ 105 | 106 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'), 107 | 108 | ]; 109 | -------------------------------------------------------------------------------- /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", "resend", "log", "array", 34 | | "failover", "roundrobin" 35 | | 36 | */ 37 | 38 | 'mailers' => [ 39 | 40 | 'smtp' => [ 41 | 'transport' => 'smtp', 42 | 'scheme' => env('MAIL_SCHEME'), 43 | 'url' => env('MAIL_URL'), 44 | 'host' => env('MAIL_HOST', '127.0.0.1'), 45 | 'port' => env('MAIL_PORT', 2525), 46 | 'username' => env('MAIL_USERNAME'), 47 | 'password' => env('MAIL_PASSWORD'), 48 | 'timeout' => null, 49 | 'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url(env('APP_URL', 'http://localhost'), PHP_URL_HOST)), 50 | ], 51 | 52 | 'ses' => [ 53 | 'transport' => 'ses', 54 | ], 55 | 56 | 'postmark' => [ 57 | 'transport' => 'postmark', 58 | // 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'), 59 | // 'client' => [ 60 | // 'timeout' => 5, 61 | // ], 62 | ], 63 | 64 | 'resend' => [ 65 | 'transport' => 'resend', 66 | ], 67 | 68 | 'sendmail' => [ 69 | 'transport' => 'sendmail', 70 | 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), 71 | ], 72 | 73 | 'log' => [ 74 | 'transport' => 'log', 75 | 'channel' => env('MAIL_LOG_CHANNEL'), 76 | ], 77 | 78 | 'array' => [ 79 | 'transport' => 'array', 80 | ], 81 | 82 | 'failover' => [ 83 | 'transport' => 'failover', 84 | 'mailers' => [ 85 | 'smtp', 86 | 'log', 87 | ], 88 | 'retry_after' => 60, 89 | ], 90 | 91 | 'roundrobin' => [ 92 | 'transport' => 'roundrobin', 93 | 'mailers' => [ 94 | 'ses', 95 | 'postmark', 96 | ], 97 | 'retry_after' => 60, 98 | ], 99 | 100 | ], 101 | 102 | /* 103 | |-------------------------------------------------------------------------- 104 | | Global "From" Address 105 | |-------------------------------------------------------------------------- 106 | | 107 | | You may wish for all emails sent by your application to be sent from 108 | | the same address. Here you may specify a name and address that is 109 | | used globally for all emails that are sent by your application. 110 | | 111 | */ 112 | 113 | 'from' => [ 114 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 115 | 'name' => env('MAIL_FROM_NAME', 'Example'), 116 | ], 117 | 118 | ]; 119 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🚀 Mini CRM - API RESTful em Laravel + DDD 2 | 3 | ![PHP](https://img.shields.io/badge/PHP-8.3-blue?logo=php) 4 | ![Laravel](https://img.shields.io/badge/Laravel-10-red?logo=laravel) 5 | ![Docker](https://img.shields.io/badge/Dockerized-Yes-blue?logo=docker) 6 | ![Tests](https://img.shields.io/badge/Tests-Passing-brightgreen) 7 | ![License](https://img.shields.io/badge/License-MIT-lightgrey) 8 | ![Status](https://img.shields.io/badge/Status-Em%20Desenvolvimento-yellow) 9 | 10 | > Projeto de portfólio com foco em arquitetura DDD, APIs RESTful e testes automatizados, visando apresentar boas práticas backend com Laravel moderno. 11 | 12 | --- 13 | 14 | ## 🧰 Tecnologias Utilizadas 15 | 16 | - ✅ PHP 8.3 17 | - ✅ Laravel 10 18 | - ✅ MySQL 8 19 | - ✅ Docker + Docker Compose 20 | - ✅ PHPUnit para testes 21 | - ✅ Arquitetura DDD 22 | - ✅ DTO Pattern 23 | - ✅ Repository Pattern 24 | - ✅ SoftDeletes 25 | - ✅ Nginx como servidor web 26 | 27 | --- 28 | 29 | ## 📦 Estrutura DDD do Projeto 30 | 31 | ``` 32 | app/ 33 | ├── Application/ # Casos de uso 34 | │ └── UseCases/ 35 | │ └── Clientes/ 36 | ├── Dominios/ # Regra de negócio 37 | │ ├── Clientes/ 38 | │ │ ├── DTO/ 39 | │ │ ├── Models/ 40 | │ │ ├── Repositories/ 41 | │ │ └── Services/ 42 | │ └── Empresas/ 43 | │ ├── DTO/ 44 | │ ├── Models/ 45 | │ ├── Repositories/ 46 | │ └── Services/ 47 | └── Interfaces/ # Interface com o mundo externo 48 | └── Http/ 49 | ├── Controllers/ 50 | └── Requests/ 51 | ``` 52 | 53 | --- 54 | 55 | ## ▶️ Como executar 56 | 57 | ### 🐳 Subir ambiente com Docker 58 | 59 | ```bash 60 | # Clonar o repositório 61 | git clone https://github.com/caiofcosta/mini-crm-ddd-laravel-api.git 62 | cd mini-crm-ddd-laravel-api 63 | 64 | # Copiar o arquivo de ambiente 65 | cp .env.example .env 66 | 67 | # Subir os containers 68 | docker-compose up -d 69 | 70 | # Instalar dependências 71 | docker exec -it mini_crm_app composer install 72 | 73 | # Gerar chave da aplicação 74 | docker exec -it mini_crm_app php artisan key:generate 75 | 76 | # Executar migrações 77 | docker exec -it mini_crm_app php artisan migrate 78 | ``` 79 | 80 | ### 🧪 Rodar os testes 81 | 82 | ```bash 83 | docker exec -it mini_crm_app php artisan test --env=testing 84 | ``` 85 | 86 | --- 87 | 88 | ## 📮 Principais Endpoints 89 | 90 | ### Clientes 91 | 92 | | Método | Endpoint | Ação | 93 | |--------|----------|------| 94 | | POST | `/api/clientes` | Cadastrar cliente | 95 | | GET | `/api/clientes` | Listar clientes (paginado) | 96 | | GET | `/api/clientes/excluidos` | Listar clientes excluídos | 97 | | GET | `/api/clientes/todos` | Listar todos os clientes (incluindo excluídos) | 98 | | PUT | `/api/clientes/{id}` | Atualizar cliente | 99 | | DELETE | `/api/clientes/{id}` | Excluir cliente (soft delete) | 100 | 101 | ### Empresas 102 | 103 | | Método | Endpoint | Ação | 104 | |--------|----------|------| 105 | | POST | `/api/empresas` | Cadastrar empresa | 106 | | GET | `/api/empresas` | Listar empresas (paginado) | 107 | | DELETE | `/api/empresas/{id}` | Excluir empresa | 108 | 109 | --- 110 | 111 | ## ✅ Testes automatizados 112 | 113 | O projeto possui testes automatizados cobrindo: 114 | 115 | - Validação de campos obrigatórios 116 | - CPF duplicado 117 | - Cliente associado à empresa 118 | - Respostas JSON esperadas 119 | - Soft deletes 120 | - Paginação 121 | 122 | Para executar os testes: 123 | 124 | ```bash 125 | docker exec -it mini_crm_app php artisan test --env=testing 126 | ``` 127 | 128 | --- 129 | 130 | ## 📝 Exemplo de Requisições 131 | 132 | ### Criar Empresa 133 | 134 | ```bash 135 | curl -X POST http://localhost:8000/api/empresas \ 136 | -H "Content-Type: application/json" \ 137 | -d '{ 138 | "nome": "Empresa Teste", 139 | "cnpj": "12345678000199", 140 | "email": "empresa@teste.com", 141 | "telefone": "11999999999" 142 | }' 143 | ``` 144 | 145 | ### Criar Cliente 146 | 147 | ```bash 148 | curl -X POST http://localhost:8000/api/clientes \ 149 | -H "Content-Type: application/json" \ 150 | -d '{ 151 | "nome": "João da Silva", 152 | "email": "joao@example.com", 153 | "telefone": "11999999999", 154 | "cpf": "12345678900", 155 | "empresa_id": 1 156 | }' 157 | ``` 158 | 159 | --- 160 | 161 | ## 👨‍💻 Autor 162 | 163 | **Caio Costa** 164 | Desenvolvedor PHP Backend | Laravel | Docker 165 | 166 | - 🔗 [LinkedIn](https://www.linkedin.com/in/caio-costa-bb736936/) 167 | - 🔗 [GitHub](https://github.com/caiofcosta) 168 | 169 | --- 170 | 171 | ## 📄 Licença 172 | 173 | Este projeto está sob a licença MIT. Veja o arquivo [LICENSE](LICENSE) para mais detalhes. 174 | -------------------------------------------------------------------------------- /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 | 'handler_with' => [ 102 | 'stream' => 'php://stderr', 103 | ], 104 | 'formatter' => env('LOG_STDERR_FORMATTER'), 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 | -------------------------------------------------------------------------------- /app/Interfaces/Http/Controllers/ClienteController.php: -------------------------------------------------------------------------------- 1 | input('per_page', 15); 29 | $search = $request->input('search'); 30 | 31 | $query = $this->repository->paginados($perPage); 32 | 33 | if ($search) { 34 | $query->where(function ($q) use ($search) { 35 | $q->where('nome', 'like', "%{$search}%") 36 | ->orWhere('email', 'like', "%{$search}%") 37 | ->orWhere('cpf', 'like', "%{$search}%"); 38 | }); 39 | } 40 | 41 | $clientes = $query->paginate($perPage); 42 | 43 | $clientes->getCollection()->transform(function (Cliente $cliente) { 44 | return ClienteListagemDTO::fromModel($cliente); 45 | }); 46 | 47 | return response()->json($clientes); 48 | } 49 | 50 | public function excluidos(Request $request): JsonResponse 51 | { 52 | $perPage = $request->input('per_page', 15); 53 | $search = $request->input('search'); 54 | 55 | $query = $this->repository->apenasExcluidos(); 56 | 57 | if ($search) { 58 | $query->where(function ($q) use ($search) { 59 | $q->where('nome', 'like', "%{$search}%") 60 | ->orWhere('email', 'like', "%{$search}%") 61 | ->orWhere('cpf', 'like', "%{$search}%"); 62 | }); 63 | } 64 | 65 | $clientes = $query->paginate($perPage); 66 | 67 | $clientes->getCollection()->transform(function (Cliente $cliente) { 68 | return ClienteListagemDTO::fromModel($cliente); 69 | }); 70 | 71 | return response()->json($clientes); 72 | } 73 | 74 | public function todos(Request $request): JsonResponse 75 | { 76 | $perPage = $request->input('per_page', 15); 77 | $search = $request->input('search'); 78 | 79 | $query = $this->repository->todosComExcluidos(); 80 | 81 | if ($search) { 82 | $query->where(function ($q) use ($search) { 83 | $q->where('nome', 'like', "%{$search}%") 84 | ->orWhere('email', 'like', "%{$search}%") 85 | ->orWhere('cpf', 'like', "%{$search}%"); 86 | }); 87 | } 88 | 89 | $clientes = $query->paginate($perPage); 90 | 91 | $clientes->getCollection()->transform(function (Cliente $cliente) { 92 | return ClienteListagemDTO::fromModel($cliente); 93 | }); 94 | 95 | return response()->json($clientes); 96 | } 97 | 98 | public function store(ClienteRequest $request): JsonResponse 99 | { 100 | try { 101 | $dto = CriarClienteDto::fromArray($request->validated()); 102 | $cliente = $this->createClienteUseCase->execute($dto); 103 | 104 | return response()->json([ 105 | 'data' => [ 106 | 'id' => $cliente->id, 107 | 'nome' => $cliente->nome, 108 | 'email' => $cliente->email, 109 | 'telefone' => $cliente->telefone, 110 | 'cpf' => $cliente->cpf, 111 | 'empresa_id' => $cliente->empresa_id, 112 | 'created_at' => $cliente->created_at, 113 | 'updated_at' => $cliente->updated_at 114 | ], 115 | 'message' => 'Cliente criado com sucesso' 116 | ], 201); 117 | } catch (ValidationException $e) { 118 | return response()->json([ 119 | 'message' => 'Dados inválidos', 120 | 'errors' => $e->errors() 121 | ], 422); 122 | } catch (\Exception $e) { 123 | return response()->json([ 124 | 'message' => 'Erro ao criar cliente', 125 | 'error' => $e->getMessage() 126 | ], 500); 127 | } 128 | } 129 | 130 | public function update(int $id, Request $request): JsonResponse 131 | { 132 | try { 133 | $dto = AtualizarClienteDTO::fromArray($request->all()); 134 | $cliente = $this->repository->atualizar($id, $dto); 135 | 136 | return response()->json([ 137 | 'id' => $cliente->id, 138 | 'nome' => $cliente->nome, 139 | 'email' => $cliente->email, 140 | 'cpf' => $cliente->cpf, 141 | 'telefone' => $cliente->telefone 142 | ]); 143 | } catch (ValidationException $e) { 144 | return response()->json([ 145 | 'message' => 'Dados inválidos', 146 | 'errors' => $e->errors() 147 | ], 422); 148 | } catch (ModelNotFoundException $e) { 149 | return response()->json([ 150 | 'message' => 'Cliente não encontrado' 151 | ], 404); 152 | } 153 | } 154 | 155 | public function destroy(int $id): JsonResponse 156 | { 157 | try { 158 | $this->service->remover($id); 159 | 160 | return response()->json([ 161 | 'mensagem' => 'Cliente removido com sucesso' 162 | ]); 163 | } catch (ModelNotFoundException $e) { 164 | return response()->json([ 165 | 'message' => 'Cliente não encontrado' 166 | ], 404); 167 | } 168 | } 169 | } -------------------------------------------------------------------------------- /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 | 'busy_timeout' => null, 41 | 'journal_mode' => null, 42 | 'synchronous' => null, 43 | ], 44 | 45 | 'mysql' => [ 46 | 'driver' => 'mysql', 47 | 'url' => env('DB_URL'), 48 | 'host' => env('DB_HOST', '127.0.0.1'), 49 | 'port' => env('DB_PORT', '3306'), 50 | 'database' => env('DB_DATABASE', 'laravel'), 51 | 'username' => env('DB_USERNAME', 'root'), 52 | 'password' => env('DB_PASSWORD', ''), 53 | 'unix_socket' => env('DB_SOCKET', ''), 54 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 55 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 56 | 'prefix' => '', 57 | 'prefix_indexes' => true, 58 | 'strict' => true, 59 | 'engine' => null, 60 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 61 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 62 | ]) : [], 63 | ], 64 | 65 | 'mariadb' => [ 66 | 'driver' => 'mariadb', 67 | 'url' => env('DB_URL'), 68 | 'host' => env('DB_HOST', '127.0.0.1'), 69 | 'port' => env('DB_PORT', '3306'), 70 | 'database' => env('DB_DATABASE', 'laravel'), 71 | 'username' => env('DB_USERNAME', 'root'), 72 | 'password' => env('DB_PASSWORD', ''), 73 | 'unix_socket' => env('DB_SOCKET', ''), 74 | 'charset' => env('DB_CHARSET', 'utf8mb4'), 75 | 'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'), 76 | 'prefix' => '', 77 | 'prefix_indexes' => true, 78 | 'strict' => true, 79 | 'engine' => null, 80 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 81 | PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 82 | ]) : [], 83 | ], 84 | 85 | 'pgsql' => [ 86 | 'driver' => 'pgsql', 87 | 'url' => env('DB_URL'), 88 | 'host' => env('DB_HOST', '127.0.0.1'), 89 | 'port' => env('DB_PORT', '5432'), 90 | 'database' => env('DB_DATABASE', 'laravel'), 91 | 'username' => env('DB_USERNAME', 'root'), 92 | 'password' => env('DB_PASSWORD', ''), 93 | 'charset' => env('DB_CHARSET', 'utf8'), 94 | 'prefix' => '', 95 | 'prefix_indexes' => true, 96 | 'search_path' => 'public', 97 | 'sslmode' => 'prefer', 98 | ], 99 | 100 | 'sqlsrv' => [ 101 | 'driver' => 'sqlsrv', 102 | 'url' => env('DB_URL'), 103 | 'host' => env('DB_HOST', 'localhost'), 104 | 'port' => env('DB_PORT', '1433'), 105 | 'database' => env('DB_DATABASE', 'laravel'), 106 | 'username' => env('DB_USERNAME', 'root'), 107 | 'password' => env('DB_PASSWORD', ''), 108 | 'charset' => env('DB_CHARSET', 'utf8'), 109 | 'prefix' => '', 110 | 'prefix_indexes' => true, 111 | // 'encrypt' => env('DB_ENCRYPT', 'yes'), 112 | // 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'), 113 | ], 114 | 115 | ], 116 | 117 | /* 118 | |-------------------------------------------------------------------------- 119 | | Migration Repository Table 120 | |-------------------------------------------------------------------------- 121 | | 122 | | This table keeps track of all the migrations that have already run for 123 | | your application. Using this information, we can determine which of 124 | | the migrations on disk haven't actually been run on the database. 125 | | 126 | */ 127 | 128 | 'migrations' => [ 129 | 'table' => 'migrations', 130 | 'update_date_on_publish' => true, 131 | ], 132 | 133 | /* 134 | |-------------------------------------------------------------------------- 135 | | Redis Databases 136 | |-------------------------------------------------------------------------- 137 | | 138 | | Redis is an open source, fast, and advanced key-value store that also 139 | | provides a richer body of commands than a typical key-value system 140 | | such as Memcached. You may define your connection settings here. 141 | | 142 | */ 143 | 144 | 'redis' => [ 145 | 146 | 'client' => env('REDIS_CLIENT', 'phpredis'), 147 | 148 | 'options' => [ 149 | 'cluster' => env('REDIS_CLUSTER', 'redis'), 150 | 'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'), 151 | 'persistent' => env('REDIS_PERSISTENT', false), 152 | ], 153 | 154 | 'default' => [ 155 | 'url' => env('REDIS_URL'), 156 | 'host' => env('REDIS_HOST', '127.0.0.1'), 157 | 'username' => env('REDIS_USERNAME'), 158 | 'password' => env('REDIS_PASSWORD'), 159 | 'port' => env('REDIS_PORT', '6379'), 160 | 'database' => env('REDIS_DB', '0'), 161 | ], 162 | 163 | 'cache' => [ 164 | 'url' => env('REDIS_URL'), 165 | 'host' => env('REDIS_HOST', '127.0.0.1'), 166 | 'username' => env('REDIS_USERNAME'), 167 | 'password' => env('REDIS_PASSWORD'), 168 | 'port' => env('REDIS_PORT', '6379'), 169 | 'database' => env('REDIS_CACHE_DB', '1'), 170 | ], 171 | 172 | ], 173 | 174 | ]; 175 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Application Environment 24 | |-------------------------------------------------------------------------- 25 | | 26 | | This value determines the "environment" your application is currently 27 | | running in. This may determine how you prefer to configure various 28 | | services the application utilizes. Set this in your ".env" file. 29 | | 30 | */ 31 | 32 | 'env' => env('APP_ENV', 'production'), 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | Application Debug Mode 37 | |-------------------------------------------------------------------------- 38 | | 39 | | When your application is in debug mode, detailed error messages with 40 | | stack traces will be shown on every error that occurs within your 41 | | application. If disabled, a simple generic error page is shown. 42 | | 43 | */ 44 | 45 | 'debug' => (bool) env('APP_DEBUG', false), 46 | 47 | /* 48 | |-------------------------------------------------------------------------- 49 | | Application URL 50 | |-------------------------------------------------------------------------- 51 | | 52 | | This URL is used by the console to properly generate URLs when using 53 | | the Artisan command line tool. You should set this to the root of 54 | | the application so that it's available within Artisan commands. 55 | | 56 | */ 57 | 58 | 'url' => env('APP_URL', 'http://localhost'), 59 | 60 | 'asset_url' => env('ASSET_URL'), 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Application Timezone 65 | |-------------------------------------------------------------------------- 66 | | 67 | | Here you may specify the default timezone for your application, which 68 | | will be used by the PHP date and date-time functions. The timezone 69 | | is set to "UTC" by default as it is suitable for most use cases. 70 | | 71 | */ 72 | 73 | 'timezone' => 'UTC', 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Application Locale Configuration 78 | |-------------------------------------------------------------------------- 79 | | 80 | | The application locale determines the default locale that will be used 81 | | by Laravel's translation / localization methods. This option can be 82 | | set to any locale for which you plan to have translation strings. 83 | | 84 | */ 85 | 86 | 'locale' => 'en', 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | Application Fallback Locale 91 | |-------------------------------------------------------------------------- 92 | | 93 | | The fallback locale determines the locale to use when the current one 94 | | is not available. You may change the value to correspond to any of 95 | | the language folders that are provided through your application. 96 | | 97 | */ 98 | 99 | 'fallback_locale' => 'en', 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Faker Locale 104 | |-------------------------------------------------------------------------- 105 | | 106 | | This locale will be used by the Faker PHP library when generating fake 107 | | data for your database seeds. For example, this will be used to get 108 | | localized telephone numbers, street address information and more. 109 | | 110 | */ 111 | 112 | 'faker_locale' => 'en_US', 113 | 114 | /* 115 | |-------------------------------------------------------------------------- 116 | | Encryption Key 117 | |-------------------------------------------------------------------------- 118 | | 119 | | This key is used by the Illuminate encrypter service and should be set 120 | | to a random, 32 character string, otherwise these encrypted strings 121 | | will not be safe. Please do this before deploying an application! 122 | | 123 | */ 124 | 125 | 'key' => env('APP_KEY'), 126 | 127 | 'cipher' => 'AES-256-CBC', 128 | 129 | /* 130 | |-------------------------------------------------------------------------- 131 | | Maintenance Mode Driver 132 | |-------------------------------------------------------------------------- 133 | | 134 | | These configuration options determine the driver used to determine and 135 | | manage Laravel's "maintenance mode" status. The "cache" driver will 136 | | allow maintenance mode to be controlled across multiple machines. 137 | | 138 | | Supported drivers: "file", "cache" 139 | | 140 | */ 141 | 142 | 'maintenance' => [ 143 | 'driver' => 'file', 144 | // 'store' => 'redis', 145 | ], 146 | 147 | /* 148 | |-------------------------------------------------------------------------- 149 | | Autoloaded Service Providers 150 | |-------------------------------------------------------------------------- 151 | | 152 | | The service providers listed here will be automatically loaded on the 153 | | request to your application. Feel free to add your own services to 154 | | this array to grant expanded functionality to your applications. 155 | | 156 | */ 157 | 158 | 'providers' => ServiceProvider::defaultProviders()->merge([ 159 | /* 160 | * Package Service Providers... 161 | */ 162 | 163 | /* 164 | * Application Service Providers... 165 | */ 166 | App\Providers\AppServiceProvider::class, 167 | App\Providers\AuthServiceProvider::class, 168 | // App\Providers\BroadcastServiceProvider::class, 169 | App\Providers\EventServiceProvider::class, 170 | App\Providers\RouteServiceProvider::class, 171 | ])->toArray(), 172 | 173 | /* 174 | |-------------------------------------------------------------------------- 175 | | Class Aliases 176 | |-------------------------------------------------------------------------- 177 | | 178 | | This array of class aliases will be registered when this application 179 | | is started. However, feel free to register as many as you wish as 180 | | the aliases are "lazy" loaded so they don't hinder performance. 181 | | 182 | */ 183 | 184 | 'aliases' => Facade::defaultAliases()->merge([ 185 | // 'Example' => App\Facades\Example::class, 186 | ])->toArray(), 187 | 188 | ]; 189 | -------------------------------------------------------------------------------- /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' => (int) 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 | -------------------------------------------------------------------------------- /resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Laravel 8 | 9 | 10 | 11 | 12 | 13 | 14 | @if (file_exists(public_path('build/manifest.json')) || file_exists(public_path('hot'))) 15 | @vite(['resources/css/app.css', 'resources/js/app.js']) 16 | @else 17 | 20 | @endif 21 | 22 | 23 |
24 | @if (Route::has('login')) 25 | 50 | @endif 51 |
52 |
53 |
54 |
55 |

Let's get started

56 |

Laravel has an incredibly rich ecosystem.
We suggest starting with the following.

57 | 113 | 120 |
121 |
122 | {{-- Laravel Logo --}} 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | {{-- Light Mode 12 SVG --}} 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | {{-- Dark Mode 12 SVG --}} 203 | 268 |
269 |
270 |
271 |
272 | 273 | @if (Route::has('login')) 274 | 275 | @endif 276 | 277 | 278 | --------------------------------------------------------------------------------