Browse Source

feat: add name para unit

Gustavo Mantovani 1 ngày trước cách đây
mục cha
commit
c97734fc3c

+ 2 - 0
app/Http/Requests/UnitRequest.php

@@ -11,6 +11,7 @@ public function rules(): array
         $isCreate = $this->isMethod('POST');
 
         $rules = [
+            'name'              => 'sometimes|required|string|max:255',
             'fantasy_name'      => 'sometimes|nullable|string|max:255',
             'social_reason'     => 'sometimes|required|string|max:255',
             'cnpj'              => 'sometimes|required|string|max:20',
@@ -55,6 +56,7 @@ public function rules(): array
 
         if ($isCreate) {
             $required = [
+                'name',
                 'social_reason',
                 'cnpj',
                 'name_responsible',

+ 1 - 0
app/Http/Resources/UnitResource.php

@@ -20,6 +20,7 @@ public function toArray(Request $request): array
     {
         return [
             'id'                 => $this->id,
+            'name'               => $this->name,
             'fantasy_name'       => $this->fantasy_name,
             'social_reason'      => $this->social_reason,
             'cnpj'               => $this->cnpj,

+ 1 - 1
app/Models/Unit.php

@@ -12,7 +12,7 @@
 
 /**
  * @property int $id
- * @property string $fantasy_name
+ * @property string|null $fantasy_name
  * @property string $social_reason
  * @property string $cnpj
  * @property string $phone_number

+ 1 - 1
app/Services/UnitService.php

@@ -33,7 +33,7 @@ public function findById(int $id): ?Unit
     public function create(array $data): Unit
     {
         $franchiseeData = [
-            'name'             => $data['fantasy_name'] ?? null,
+            'name'             => $data['name'],
             'cnpj'             => $data['cnpj'],
             'cpf'              => null,
             'rg'               => null,

+ 22 - 0
database/migrations/2026_08_03_000002_add_name_to_units_table.php

@@ -0,0 +1,22 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    public function up(): void
+    {
+        Schema::table('units', function (Blueprint $table) {
+            $table->string('name')->nullable()->after('id');
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::table('units', function (Blueprint $table) {
+            $table->dropColumn('name');
+        });
+    }
+};