diff --git a/.env.example b/.env.example index 8495881..15236da 100644 --- a/.env.example +++ b/.env.example @@ -25,8 +25,8 @@ REDIS_PASSWORD=null REDIS_PORT=6379 MAIL_MAILER=smtp -MAIL_HOST=smtp.mailtrap.io -MAIL_PORT=2525 +MAIL_HOST=dev-mailpit +MAIL_PORT=1025 MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null diff --git a/app/Http/Controllers/Bo/ClaimController.php b/app/Http/Controllers/Bo/ClaimController.php index bd3ed5c..a176e37 100644 --- a/app/Http/Controllers/Bo/ClaimController.php +++ b/app/Http/Controllers/Bo/ClaimController.php @@ -128,12 +128,12 @@ class ClaimController extends Controller */ public function edit(Claim $claim): \Illuminate\Contracts\View\View { - $customerClaimModels = !is_null($claim->customer) ? Claim::query() - ->whereNotNull('customer_id') + $customerClaimModels = !is_null($claim->customerInfos) ? Claim::query() + ->where('hashcode', $claim->customerInfos->hashcode) ->whereHas('brand', fn($q) => $q->whereKey($claim->brand->getKey())) - ->whereHas('customer', fn($q) => $q->whereKey($claim->customer->getKey())) ->whereNot('id', $claim->getKey()) - ->whereNot('status', ClaimStatus::treated)->paginate($this->jsonItemPerPagination) : collect(); + ->paginate($this->jsonItemPerPagination) : collect(); + $brandModels = CollectionHelper::paginate( Brand::getUserAssociatedBrands(), $this->jsonItemPerPagination, @@ -147,7 +147,6 @@ class ClaimController extends Controller ClaimMailTemplate::getAllModelsFromBrand($claim->brand->getKey()), $this->jsonItemPerPagination, ); - $customerModel = CustomerInfo::query()->where('hashcode', $claim->hashcode)->first(); return view('bo.pages.claims.edit', [ 'claimModel' => $claim->load(['brand', 'claimSubject']), @@ -156,7 +155,7 @@ class ClaimController extends Controller 'claimMessageModels' => $claimMessageModels, 'claimSubjectModels' => $claimSubjectModels, 'claimTemplateModels' => $claimTemplateModels, - 'customerModel' => $customerModel, + 'customerInfoModel' => $claim->customerInfos, ]); } diff --git a/app/Models/Claim.php b/app/Models/Claim.php index eeb4559..6532852 100644 --- a/app/Models/Claim.php +++ b/app/Models/Claim.php @@ -170,6 +170,22 @@ class Claim extends Model implements IsExportable // * METHODS + /** + * Get CustomerInfos + * + * If Customer Haschcode <> null + * + * @return CustomerInfo|null + */ + public function getCustomerInfosAttribute(): CustomerInfo|null + { + //FIXME: Rename en customer_info_hashcode + if (!is_null($this->hashcode)) { + return CustomerInfo::query()->where('hashcode', $this->hashcode)->first(); + } + return null; + } + /** * Convert the integer to base 36 and make uppercase. * diff --git a/database/migrations/2025_10_06_142426_alter_claim_customer_association.php b/database/migrations/2025_10_06_142426_alter_claim_customer_association.php index bd07b47..ac2ce39 100644 --- a/database/migrations/2025_10_06_142426_alter_claim_customer_association.php +++ b/database/migrations/2025_10_06_142426_alter_claim_customer_association.php @@ -16,7 +16,7 @@ return new class extends Migration Schema::table('claims', function (Blueprint $table) { $table->dropForeign('claims_customer_id_foreign'); $table->dropColumn('customer_id'); - $table->string('hashcode')->nullable()->unique()->after('id'); + $table->string('hashcode')->nullable()->comment('Claim associated Customer infos by Hashcode.')->after('id'); }); } diff --git a/resources/views/bo/pages/claims/edit.blade.php b/resources/views/bo/pages/claims/edit.blade.php index a8abeac..d33d1b1 100644 --- a/resources/views/bo/pages/claims/edit.blade.php +++ b/resources/views/bo/pages/claims/edit.blade.php @@ -31,10 +31,10 @@ {{ trim(sprintf('%s %s', $claimModel->first_name, $claimModel->last_name)) }}
{{ e($claimModel->email) }}
- @if ($customerModel && auth()->user()->can('view', \App\Models\Customer::class)) + @if ($customerInfoModel && auth()->user()->can('view', \App\Models\Customer::class)) {{ __('Lien vers la fiche client') }} @@ -47,7 +47,10 @@ @endifFichier: