Ver Fonte

fix: middleware para transformar 'null' em null (problema quando tem multipart data) e ajuste em unit para deixar phone_number nullable e cell_number required no request

Gustavo Mantovani há 1 dia atrás
pai
commit
349e0ff87c

+ 20 - 0
app/Http/Middleware/ConvertStringNullToNull.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Illuminate\Foundation\Http\Middleware\TransformsRequest;
+
+class ConvertStringNullToNull extends TransformsRequest
+{
+    /**
+     * Transform the given value.
+     *
+     * @param  string  $key
+     * @param  mixed  $value
+     * @return mixed
+     */
+    protected function transform($key, $value)
+    {
+        return $value === 'null' ? null : $value;
+    }
+}

+ 3 - 3
app/Http/Requests/UnitRequest.php

@@ -27,8 +27,8 @@ public function rules(): array
             'state_id'           => 'sometimes|required|integer|exists:states,id',
             'email'              => 'sometimes|required|email|max:255',
             'secondary_email'    => 'sometimes|nullable|email|max:255',
-            'phone_number'       => 'sometimes|required|string|max:20',
-            'cell_number'        => 'sometimes|nullable|string|max:20',
+            'phone_number'       => 'sometimes|nullable|string|max:20',
+            'cell_number'        => 'sometimes|required|string|max:20',
             'avatar'             => 'sometimes|nullable|image|max:20480',
             'contracts'          => 'sometimes|nullable|array',
             'contracts.*'        => 'file|mimes:pdf|max:20480',
@@ -67,7 +67,7 @@ public function rules(): array
                 'city_id',
                 'state_id',
                 'email',
-                'phone_number',
+                'cell_number',
             ];
 
             foreach ($required as $field) {

+ 1 - 1
app/Models/Franchisee.php

@@ -11,7 +11,7 @@
 /**
  * @property int $id
  * @property string $name
- * @property Cpf|null $cpf
+ * @property \App\ValueObjects\Cpf|null $cpf
  * @property string|null $rg
  * @property string|null $cnpj
  * @property string|null $phone

+ 1 - 1
app/Models/StudentResponsible.php

@@ -13,7 +13,7 @@
  * @property int $student_id
  * @property string $name
  * @property \Illuminate\Support\Carbon $birth_date
- * @property Cpf $cpf
+ * @property \App\ValueObjects\Cpf $cpf
  * @property string|null $gender
  * @property string $degree
  * @property string $email

+ 2 - 0
app/Models/Unit.php

@@ -32,6 +32,7 @@
  * @property \Illuminate\Support\Carbon|null $updated_at
  * @property \Illuminate\Support\Carbon|null $deleted_at
  * @property string|null $complement
+ * @property string|null $name
  * @property-read \App\Models\City $city
  * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Franchisee> $franchisees
  * @property-read int|null $franchisees_count
@@ -56,6 +57,7 @@
  * @method static \Illuminate\Database\Eloquent\Builder<static>|Unit whereEmail($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|Unit whereFantasyName($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|Unit whereId($value)
+ * @method static \Illuminate\Database\Eloquent\Builder<static>|Unit whereName($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|Unit whereNameResponsible($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|Unit whereNeighborhood($value)
  * @method static \Illuminate\Database\Eloquent\Builder<static>|Unit wherePhoneNumber($value)

+ 1 - 1
app/Models/UnitPartner.php

@@ -14,7 +14,7 @@
  * @property string $name
  * @property string|null $social_name
  * @property string|null $role
- * @property Cpf $cpf
+ * @property \App\ValueObjects\Cpf $cpf
  * @property string|null $rg
  * @property \Illuminate\Support\Carbon|null $birth_date
  * @property numeric|null $participation

+ 1 - 1
app/Models/User.php

@@ -25,7 +25,7 @@
  * @property \Illuminate\Support\Carbon|null $updated_at
  * @property string|null $deleted_at
  * @property \Illuminate\Support\Carbon|null $last_login_at
- * @property Cpf|null $cpf
+ * @property \App\ValueObjects\Cpf|null $cpf
  * @property string|null $avatar_url
  * @property int|null $state_id
  * @property string|null $phone

+ 2 - 2
app/Services/UnitService.php

@@ -37,8 +37,8 @@ public function create(array $data): Unit
             'cnpj'             => $data['cnpj'],
             'cpf'              => null,
             'rg'               => null,
-            'phone'            => $data['cell_number'] ?? null,
-            'cellphone_number' => $data['phone_number'] ?? null,
+            'phone'            => $data['phone_number'] ?? null,
+            'cellphone_number' => $data['cell_number'],
             'street'           => $data['street'],
             'address_number'   => $data['address_number'] ?? null,
             'neighborhood'     => $data['neighborhood'],

+ 6 - 1
bootstrap/app.php

@@ -6,6 +6,7 @@
 use Illuminate\Console\Scheduling\Schedule;
 use App\Http\Middleware\SetUserLanguage;
 use App\Http\Middleware\CheckPermission;
+use App\Http\Middleware\ConvertStringNullToNull;
 use App\Http\Middleware\PerformanceMonitor;
 use Laravel\Sanctum\Http\Middleware\CheckForAnyAbility;
 use App\Tasks\DeleteExpiredTokens;
@@ -20,7 +21,11 @@
     )
     ->withMiddleware(function (Middleware $middleware) {
         // $middleware->statefulApi();
-        $middleware->append([SetUserLanguage::class, PerformanceMonitor::class]);
+        $middleware->append([
+            ConvertStringNullToNull::class,
+            SetUserLanguage::class,
+            PerformanceMonitor::class,
+        ]);
         $middleware->alias([
             'permission' => CheckPermission::class,
             'ability' => CheckForAnyAbility::class,

+ 28 - 0
database/migrations/2026_08_03_151901_update_unit_phone_requirements.php

@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('units', function (Blueprint $table) {
+            $table->string('phone_number')->nullable()->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('units', function (Blueprint $table) {
+            $table->string('phone_number')->nullable(false)->change();
+        });
+    }
+};

+ 42 - 1
lang/en/validation.php

@@ -194,6 +194,47 @@
     |
     */
 
-    'attributes' => [],
+    'attributes' => [
+        'name' => 'Name',
+        'fantasy_name' => 'Trade Name',
+        'social_reason' => 'Corporate Name',
+        'cnpj' => 'CNPJ',
+        'state_registration' => 'State Registration',
+        'name_responsible' => 'Responsible Person’s Name',
+        'street' => 'Street',
+        'address_number' => 'Address Number',
+        'postal_code' => 'Postal Code',
+        'neighborhood' => 'Neighborhood',
+        'complement' => 'Address Complement',
+        'city_id' => 'City',
+        'state_id' => 'State',
+        'email' => 'Email',
+        'secondary_email' => 'Administrative Email',
+        'phone_number' => 'Landline',
+        'cell_number' => 'Mobile Phone',
+        'avatar' => 'Logo',
+        'contracts' => 'Contracts',
+        'contracts.*' => 'Contract',
+        'partners' => 'Partners',
+        'partners.*.name' => 'Partner’s Name',
+        'partners.*.cpf' => 'Partner’s CPF',
+        'partners.*.social_name' => 'Partner’s Social Name',
+        'partners.*.role' => 'Partner’s Role',
+        'partners.*.rg' => 'Partner’s ID',
+        'partners.*.birth_date' => 'Partner’s Date of Birth',
+        'partners.*.participation' => 'Partner’s Ownership Percentage',
+        'partners.*.email' => 'Partner’s Email',
+        'partners.*.secondary_email' => 'Partner’s Administrative Email',
+        'partners.*.phone_number' => 'Partner’s Landline',
+        'partners.*.cell_number' => 'Partner’s Mobile Phone',
+        'partners.*.postal_code' => 'Partner’s Postal Code',
+        'partners.*.street' => 'Partner’s Street',
+        'partners.*.address_number' => 'Partner’s Address Number',
+        'partners.*.neighborhood' => 'Partner’s Neighborhood',
+        'partners.*.complement' => 'Partner’s Address Complement',
+        'partners.*.city_id' => 'Partner’s City',
+        'partners.*.state_id' => 'Partner’s State',
+        'partners.*.avatar' => 'Partner’s Photo',
+    ],
 
 ];

+ 42 - 1
lang/es/validation.php

@@ -194,6 +194,47 @@
     |
     */
 
-    'attributes' => [],
+    'attributes' => [
+        'name' => 'Nombre',
+        'fantasy_name' => 'Nombre Comercial',
+        'social_reason' => 'Razón Social',
+        'cnpj' => 'CNPJ',
+        'state_registration' => 'Registro Estatal',
+        'name_responsible' => 'Nombre del Responsable',
+        'street' => 'Calle',
+        'address_number' => 'Número',
+        'postal_code' => 'Código Postal',
+        'neighborhood' => 'Barrio',
+        'complement' => 'Complemento de Dirección',
+        'city_id' => 'Ciudad',
+        'state_id' => 'Estado',
+        'email' => 'Correo Electrónico',
+        'secondary_email' => 'Correo Electrónico Administrativo',
+        'phone_number' => 'Teléfono Fijo',
+        'cell_number' => 'Celular',
+        'avatar' => 'Logotipo',
+        'contracts' => 'Contratos',
+        'contracts.*' => 'Contrato',
+        'partners' => 'Socios',
+        'partners.*.name' => 'Nombre del Socio',
+        'partners.*.cpf' => 'CPF del Socio',
+        'partners.*.social_name' => 'Nombre Social del Socio',
+        'partners.*.role' => 'Cargo del Socio',
+        'partners.*.rg' => 'Documento de Identidad del Socio',
+        'partners.*.birth_date' => 'Fecha de Nacimiento del Socio',
+        'partners.*.participation' => 'Participación del Socio',
+        'partners.*.email' => 'Correo Electrónico del Socio',
+        'partners.*.secondary_email' => 'Correo Electrónico Administrativo del Socio',
+        'partners.*.phone_number' => 'Teléfono Fijo del Socio',
+        'partners.*.cell_number' => 'Celular del Socio',
+        'partners.*.postal_code' => 'Código Postal del Socio',
+        'partners.*.street' => 'Calle del Socio',
+        'partners.*.address_number' => 'Número del Socio',
+        'partners.*.neighborhood' => 'Barrio del Socio',
+        'partners.*.complement' => 'Complemento de Dirección del Socio',
+        'partners.*.city_id' => 'Ciudad del Socio',
+        'partners.*.state_id' => 'Estado del Socio',
+        'partners.*.avatar' => 'Foto del Socio',
+    ],
 
 ];

+ 42 - 1
lang/pt/validation.php

@@ -195,6 +195,47 @@
     |
     */
 
-    'attributes' => [],
+    'attributes' => [
+        'name' => 'Nome',
+        'fantasy_name' => 'Nome Fantasia',
+        'social_reason' => 'Razão Social',
+        'cnpj' => 'CNPJ',
+        'state_registration' => 'Inscrição Estadual',
+        'name_responsible' => 'Nome do Responsável',
+        'street' => 'Rua',
+        'address_number' => 'Número',
+        'postal_code' => 'CEP',
+        'neighborhood' => 'Bairro',
+        'complement' => 'Complemento',
+        'city_id' => 'Cidade',
+        'state_id' => 'Estado',
+        'email' => 'E-mail',
+        'secondary_email' => 'E-mail Administrativo',
+        'phone_number' => 'Telefone Fixo',
+        'cell_number' => 'Celular',
+        'avatar' => 'Logotipo',
+        'contracts' => 'Contratos',
+        'contracts.*' => 'Contrato',
+        'partners' => 'Sócios',
+        'partners.*.name' => 'Nome do Sócio',
+        'partners.*.cpf' => 'CPF do Sócio',
+        'partners.*.social_name' => 'Nome Social do Sócio',
+        'partners.*.role' => 'Cargo do Sócio',
+        'partners.*.rg' => 'RG do Sócio',
+        'partners.*.birth_date' => 'Data de Nascimento do Sócio',
+        'partners.*.participation' => 'Participação do Sócio',
+        'partners.*.email' => 'E-mail do Sócio',
+        'partners.*.secondary_email' => 'E-mail Administrativo do Sócio',
+        'partners.*.phone_number' => 'Telefone Fixo do Sócio',
+        'partners.*.cell_number' => 'Celular do Sócio',
+        'partners.*.postal_code' => 'CEP do Sócio',
+        'partners.*.street' => 'Rua do Sócio',
+        'partners.*.address_number' => 'Número do Sócio',
+        'partners.*.neighborhood' => 'Bairro do Sócio',
+        'partners.*.complement' => 'Complemento do Sócio',
+        'partners.*.city_id' => 'Cidade do Sócio',
+        'partners.*.state_id' => 'Estado do Sócio',
+        'partners.*.avatar' => 'Foto do Sócio',
+    ],
 
 ];