From a3a84446f8960a4acd97ad6bf1076ecd28e937fe Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Thu, 24 Jul 2025 11:32:12 +0200 Subject: [PATCH] feat: :card_file_box: add claims tables, seeder and relations --- app/Console/Commands/UserCreate.php | 12 +- app/Enums/Claims/ClaimMessageType.php | 21 ++ app/Enums/Claims/ClaimStatus.php | 25 ++ app/Enums/Claims/ClaimType.php | 23 ++ app/Enums/Users/RoleEnum.php | 2 + .../Requests/Bo/Users/StoreUserRequest.php | 22 +- app/Models/ActivityLog.php | 2 +- app/Models/Answer.php | 4 +- app/Models/Brand.php | 70 ++++- app/Models/BrandStat.php | 6 +- app/Models/Claim.php | 106 +++++++ app/Models/ClaimMailTemplate.php | 42 +++ app/Models/ClaimMessage.php | 62 ++++ app/Models/ClaimSubject.php | 50 ++++ app/Models/Customer.php | 20 +- app/Models/CustomerInfo.php | 8 +- app/Models/CustomerLogin.php | 26 +- app/Models/CustomerOptInHistory.php | 6 +- app/Models/Question.php | 8 +- app/Models/Service.php | 10 +- app/Models/ServiceStat.php | 10 +- app/Models/SingleOptin.php | 4 +- app/Models/User.php | 12 +- app/Traits/Models/MiniCrudModel.php | 10 +- composer.json | 3 +- composer.lock | 270 ++++++++++++++++++ database/factories/AnswerFactory.php | 2 +- database/factories/BrandFactory.php | 7 +- database/factories/ClaimFactory.php | 44 +++ .../factories/ClaimMailTemplateFactory.php | 31 ++ database/factories/ClaimMessageFactory.php | 34 +++ database/factories/ClaimSubjectFactory.php | 30 ++ database/factories/CustomerFactory.php | 2 +- database/factories/CustomerInfoFactory.php | 22 +- database/factories/CustomerLoginFactory.php | 6 +- database/factories/QuestionFactory.php | 2 +- database/factories/ServiceFactory.php | 2 +- database/factories/UserFactory.php | 8 +- .../assets/brands/default-logo-550x550.jpg | Bin 0 -> 7105 bytes ...7_24_091926_add_fields_to_brands_table.php | 44 +++ ..._092956_create_brand_users_pivot_table.php | 33 +++ ...2413_create_claim_mail_templates_table.php | 36 +++ ..._24_110652_create_claim_subjects_table.php | 35 +++ .../2025_07_24_113251_create_claims_table.php | 53 ++++ ...2025_07_24_122149_claim_messages_table.php | 38 +++ database/seeders/BrandSeeder.php | 12 +- database/seeders/BrandStatSeeder.php | 12 +- database/seeders/ClaimMailTemplateSeeder.php | 19 ++ database/seeders/ClaimMessageSeeder.php | 19 ++ database/seeders/ClaimSeeder.php | 19 ++ database/seeders/ClaimSubjectSeeder.php | 19 ++ database/seeders/DatabaseSeeder.php | 6 +- database/seeders/UserSeeder.php | 8 +- 53 files changed, 1262 insertions(+), 115 deletions(-) create mode 100644 app/Enums/Claims/ClaimMessageType.php create mode 100644 app/Enums/Claims/ClaimStatus.php create mode 100644 app/Enums/Claims/ClaimType.php create mode 100644 app/Models/Claim.php create mode 100644 app/Models/ClaimMailTemplate.php create mode 100644 app/Models/ClaimMessage.php create mode 100644 app/Models/ClaimSubject.php create mode 100644 database/factories/ClaimFactory.php create mode 100644 database/factories/ClaimMailTemplateFactory.php create mode 100644 database/factories/ClaimMessageFactory.php create mode 100644 database/factories/ClaimSubjectFactory.php create mode 100644 database/factories/assets/brands/default-logo-550x550.jpg create mode 100644 database/migrations/2025_07_24_091926_add_fields_to_brands_table.php create mode 100644 database/migrations/2025_07_24_092956_create_brand_users_pivot_table.php create mode 100644 database/migrations/2025_07_24_102413_create_claim_mail_templates_table.php create mode 100644 database/migrations/2025_07_24_110652_create_claim_subjects_table.php create mode 100644 database/migrations/2025_07_24_113251_create_claims_table.php create mode 100644 database/migrations/2025_07_24_122149_claim_messages_table.php create mode 100644 database/seeders/ClaimMailTemplateSeeder.php create mode 100644 database/seeders/ClaimMessageSeeder.php create mode 100644 database/seeders/ClaimSeeder.php create mode 100644 database/seeders/ClaimSubjectSeeder.php diff --git a/app/Console/Commands/UserCreate.php b/app/Console/Commands/UserCreate.php index 533eb23..d9cee85 100644 --- a/app/Console/Commands/UserCreate.php +++ b/app/Console/Commands/UserCreate.php @@ -173,11 +173,12 @@ class UserCreate extends Command $tmp = $this->choice( 'Select his role', [ - Str::ucFirst(RoleEnum::conceptor->label()), - Str::ucFirst(RoleEnum::admin->label()), - Str::ucFirst(RoleEnum::visitor->label()) + RoleEnum::conceptor->name, + RoleEnum::admin->name, + RoleEnum::visitor->name, + RoleEnum::marketing->name, ], - Str::ucFirst(RoleEnum::visitor->label()), + RoleEnum::visitor->name, ); if ($tmp === Str::ucFirst(RoleEnum::conceptor->label())) { $tmp = RoleEnum::conceptor; @@ -188,6 +189,9 @@ class UserCreate extends Command if ($tmp === Str::ucFirst(RoleEnum::visitor->label())) { $tmp = RoleEnum::visitor; } + if ($tmp === RoleEnum::marketing->name) { + $tmp = RoleEnum::marketing; + } $validator = Validator::make(['role' => $tmp], [ 'role' => 'required' ]); diff --git a/app/Enums/Claims/ClaimMessageType.php b/app/Enums/Claims/ClaimMessageType.php new file mode 100644 index 0000000..5c2aef9 --- /dev/null +++ b/app/Enums/Claims/ClaimMessageType.php @@ -0,0 +1,21 @@ +name => 'Automatique', + self::human->name => 'Humain', + ]; +} diff --git a/app/Enums/Claims/ClaimStatus.php b/app/Enums/Claims/ClaimStatus.php new file mode 100644 index 0000000..068a16d --- /dev/null +++ b/app/Enums/Claims/ClaimStatus.php @@ -0,0 +1,25 @@ +name => 'Non traitée', + self::treated->name => 'Traitée', + self::sentDigital->name => 'Transférée au service Digital', + self::sentMarketing->name => 'Retournée au Marketing', + ]; +} diff --git a/app/Enums/Claims/ClaimType.php b/app/Enums/Claims/ClaimType.php new file mode 100644 index 0000000..c44bd65 --- /dev/null +++ b/app/Enums/Claims/ClaimType.php @@ -0,0 +1,23 @@ +name => 'Classique', + self::br->name => 'BR', + self::rgpd->name => 'RGPD', + ]; +} diff --git a/app/Enums/Users/RoleEnum.php b/app/Enums/Users/RoleEnum.php index 53b5ada..4a30c1e 100644 --- a/app/Enums/Users/RoleEnum.php +++ b/app/Enums/Users/RoleEnum.php @@ -11,6 +11,7 @@ enum RoleEnum: int case conceptor = 1; case admin = 2; case visitor = 3; + case marketing = 4; /** * Optionnal labels definition. @@ -19,5 +20,6 @@ enum RoleEnum: int self::conceptor->name => 'Concepteur', self::admin->name => 'Administrateur', self::visitor->name => 'Visiteur', + self::marketing->name => 'Marketing', ]; } diff --git a/app/Http/Requests/Bo/Users/StoreUserRequest.php b/app/Http/Requests/Bo/Users/StoreUserRequest.php index ffa3d18..26dccdc 100644 --- a/app/Http/Requests/Bo/Users/StoreUserRequest.php +++ b/app/Http/Requests/Bo/Users/StoreUserRequest.php @@ -24,7 +24,7 @@ class StoreUserRequest extends FormRequest * * @return void */ - protected function prepareForValidation() + protected function prepareForValidation(): void { $this->merge([ 'published' => $this->published ? true : false @@ -40,9 +40,9 @@ class StoreUserRequest extends FormRequest { return [ 'first_name' => 'required|string|min:3|max:255', - 'last_name' => 'required|string|min:3|max:255', - 'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email', - 'password' => [ + 'last_name' => 'required|string|min:3|max:255', + 'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email', + 'password' => [ 'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8) ->letters() ->mixedCase() @@ -50,8 +50,8 @@ class StoreUserRequest extends FormRequest ->symbols() ->uncompromised() ], - 'role' => ['required', new Enum(RoleEnum::class)], - 'published' => 'required|boolean', + 'role' => ['required', new Enum(RoleEnum::class)], + 'published' => 'required|boolean', ]; } @@ -64,11 +64,11 @@ class StoreUserRequest extends FormRequest { return [ 'first_name' => trans('validation.attributes.first_name'), - 'last_name' => trans('validation.attributes.last_name'), - 'email' => trans('validation.attributes.email'), - 'password' => trans('validation.attributes.password'), - 'role' => trans('validation.attributes.role'), - 'published' => trans('validation.custom.publication') + 'last_name' => trans('validation.attributes.last_name'), + 'email' => trans('validation.attributes.email'), + 'password' => trans('validation.attributes.password'), + 'role' => trans('validation.attributes.role'), + 'published' => trans('validation.custom.publication') ]; } } diff --git a/app/Models/ActivityLog.php b/app/Models/ActivityLog.php index f696475..235f4bf 100644 --- a/app/Models/ActivityLog.php +++ b/app/Models/ActivityLog.php @@ -51,7 +51,7 @@ class ActivityLog extends Model /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'is_anonymous' => 'bool', diff --git a/app/Models/Answer.php b/app/Models/Answer.php index 2191813..f7e7615 100644 --- a/app/Models/Answer.php +++ b/app/Models/Answer.php @@ -22,7 +22,7 @@ class Answer extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'answer', @@ -31,7 +31,7 @@ class Answer extends Model // * RELATIONS /** - * Question BelongsTo relation. + * Question belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/Brand.php b/app/Models/Brand.php index 0f24486..027326e 100644 --- a/app/Models/Brand.php +++ b/app/Models/Brand.php @@ -8,10 +8,14 @@ use Illuminate\Database\Eloquent\Model; use Rennokki\QueryCache\Traits\QueryCacheable; /** - * @property integer $id Id. - * @property string $name Name. - * @property-read \Illuminate\Support\Carbon $created_at Created date. - * @property-read \Illuminate\Support\Carbon $updated_at Updated date. + * @property integer $id Brand id. + * @property string $name Brand name. + * @property string $logo Brand logo. + * @property string $url Brand url link. + * @property string $url_claim Brand associative url claim. + * @property string $domain Brand domain. + * @property-read \Illuminate\Support\Carbon $created_at Brand created date. + * @property-read \Illuminate\Support\Carbon $updated_at Brand updated date. * * @property-read \Illuminate\Database\Eloquent\Collection * $services Service HasMany relation. @@ -40,10 +44,14 @@ class Brand extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'name', + 'logo', + 'url', + 'url_claim', + 'domain', ]; /** @@ -64,7 +72,7 @@ class Brand extends Model * * ! This is used to flush caching * - * @return array + * @return array */ protected function getCacheBaseTags(): array { @@ -97,7 +105,7 @@ class Brand extends Model // * RELATIONS /** - * Service hasMany relation. + * Service has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -107,7 +115,7 @@ class Brand extends Model } /** - * Question hasMany relation. + * Question has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -117,7 +125,7 @@ class Brand extends Model } /** - * CustomerInfo hasMany relation. + * CustomerInfo has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -127,7 +135,7 @@ class Brand extends Model } /** - * ServiceStat hasMany relation. + * ServiceStat has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -137,7 +145,7 @@ class Brand extends Model } /** - * SingleOptin hasMany relation. + * SingleOptin has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -146,6 +154,46 @@ class Brand extends Model return $this->hasMany(SingleOptin::class); } + /** + * Users many to many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(User::class, 'brand_users'); + } + + /** + * Claim has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Claim::class); + } + + /** + * ClaimSubject has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claimSubjects(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(ClaimSubject::class); + } + + /** + * ClaimMailTemplate has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claimMailTemplates(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(ClaimMailTemplate::class); + } + // * METHODS /** diff --git a/app/Models/BrandStat.php b/app/Models/BrandStat.php index db44d55..67bd961 100644 --- a/app/Models/BrandStat.php +++ b/app/Models/BrandStat.php @@ -28,7 +28,7 @@ class BrandStat extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'active', @@ -42,7 +42,7 @@ class BrandStat extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ public $casts = [ 'created_at' => 'date', @@ -65,7 +65,7 @@ class BrandStat extends Model // * RELATIONS /** - * Brand hasMany relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/Claim.php b/app/Models/Claim.php new file mode 100644 index 0000000..2620bc2 --- /dev/null +++ b/app/Models/Claim.php @@ -0,0 +1,106 @@ + + */ + protected $fillable = [ + 'reference', + 'first_name', + 'last_name', + 'email', + 'address', + 'city', + 'postcode', + 'file', + 'message', + 'type', + 'status', + 'brand_id', + 'subject_id', + 'customer_id', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'type' => ClaimType::class, + 'status' => ClaimStatus::class, + ]; + + // * RELATIONS + + /** + * Brand belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Brand::class); + } + + /** + * ClaimSubject subject belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function claimSubject(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(ClaimSubject::class); + } + + /** + * Customer subject belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function customer(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Customer::class); + } + + /** + * ClaimMessage has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claimMessages(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(ClaimMessage::class); + } +} diff --git a/app/Models/ClaimMailTemplate.php b/app/Models/ClaimMailTemplate.php new file mode 100644 index 0000000..d9df387 --- /dev/null +++ b/app/Models/ClaimMailTemplate.php @@ -0,0 +1,42 @@ + + */ + protected $fillable = [ + 'label', + 'content', + 'brand_id', + ]; + + // * RELATIONS + + /** + * Brand belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Brand::class); + } +} diff --git a/app/Models/ClaimMessage.php b/app/Models/ClaimMessage.php new file mode 100644 index 0000000..e28435d --- /dev/null +++ b/app/Models/ClaimMessage.php @@ -0,0 +1,62 @@ + + */ + protected $fillable = [ + 'content', + 'type', + 'claim_id', + 'user_id', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'type' => ClaimMessageType::class, + ]; + + // * RELATIONS + + /** + * Claim belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function claim(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Claim::class); + } + + /** + * User belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(User::class); + } +} diff --git a/app/Models/ClaimSubject.php b/app/Models/ClaimSubject.php new file mode 100644 index 0000000..7b8fe3f --- /dev/null +++ b/app/Models/ClaimSubject.php @@ -0,0 +1,50 @@ + + */ + protected $fillable = [ + 'label', + 'brand_id', + ]; + + // * RELATIONS + + /** + * Brand belongs to relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Brand::class); + } + + /** + * Claim has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Claim::class); + } +} diff --git a/app/Models/Customer.php b/app/Models/Customer.php index b03dbd2..2cf6bbe 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -36,7 +36,7 @@ class Customer extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'email', @@ -45,7 +45,7 @@ class Customer extends Model // * RELATIONS /** - * CustomerInfo hasMany relation. + * CustomerInfo has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -55,7 +55,7 @@ class Customer extends Model } /** - * CustomerLogin hasMany relation. + * CustomerLogin has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -65,7 +65,7 @@ class Customer extends Model } /** - * CustomerOptInHistory hasMany relation. + * CustomerOptInHistory has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -75,7 +75,7 @@ class Customer extends Model } /** - * Customer Brand belongsToMany relation. + * Customer Brand belongs to many relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ @@ -94,6 +94,16 @@ class Customer extends Model return $this->morphToMany(Answer::class, 'model', 'model_answer', 'model_id', 'answer_id'); } + /** + * Claim has many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function claims(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Claim::class); + } + // * METHODS /** diff --git a/app/Models/CustomerInfo.php b/app/Models/CustomerInfo.php index f45eba8..8a85190 100644 --- a/app/Models/CustomerInfo.php +++ b/app/Models/CustomerInfo.php @@ -36,7 +36,7 @@ class CustomerInfo extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'firstname', @@ -54,7 +54,7 @@ class CustomerInfo extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'country' => Country::class, @@ -83,7 +83,7 @@ class CustomerInfo extends Model // * RELATIONS /** - * Customer BelongsTo relation. + * Customer belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -93,7 +93,7 @@ class CustomerInfo extends Model } /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/CustomerLogin.php b/app/Models/CustomerLogin.php index 185b44f..146d240 100644 --- a/app/Models/CustomerLogin.php +++ b/app/Models/CustomerLogin.php @@ -23,28 +23,28 @@ class CustomerLogin extends Model { use HasFactory; - /** - * The model's attributes. - * - * @var array - */ - protected $attributes = [ - 'status' => false, - ]; - /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'password', ]; + /** + * The model's attributes. + * + * @var array + */ + protected $attributes = [ + 'status' => false, + ]; + /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'status' => 'bool', @@ -73,7 +73,7 @@ class CustomerLogin extends Model // * RELATIONS /** - * Customer BelongsTo relation. + * Customer belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -83,7 +83,7 @@ class CustomerLogin extends Model } /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/CustomerOptInHistory.php b/app/Models/CustomerOptInHistory.php index e01798a..dc4a0a5 100644 --- a/app/Models/CustomerOptInHistory.php +++ b/app/Models/CustomerOptInHistory.php @@ -30,7 +30,7 @@ class CustomerOptInHistory extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'new_value' => 'bool', @@ -39,7 +39,7 @@ class CustomerOptInHistory extends Model // * RELATIONS /** - * Customer BelongsTo relation. + * Customer belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -49,7 +49,7 @@ class CustomerOptInHistory extends Model } /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/Question.php b/app/Models/Question.php index c52efad..e92c814 100644 --- a/app/Models/Question.php +++ b/app/Models/Question.php @@ -26,7 +26,7 @@ class Question extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'question', @@ -37,7 +37,7 @@ class Question extends Model /** * Map attribute names to enum classes. * - * @var array + * @var array */ protected $casts = [ 'type' => QuestionType::class, @@ -46,7 +46,7 @@ class Question extends Model // * RELATIONS /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -56,7 +56,7 @@ class Question extends Model } /** - * Answer Has many relation. + * Answer has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ diff --git a/app/Models/Service.php b/app/Models/Service.php index b8b6cb0..782c5e8 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -44,7 +44,7 @@ class Service extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'name', @@ -54,7 +54,7 @@ class Service extends Model /** * The attributes that should be cast to native types. * - * @var array + * @var array */ protected $casts = [ 'bearer_token_date' => 'datetime', @@ -102,7 +102,7 @@ class Service extends Model // * RELATIONS /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -112,7 +112,7 @@ class Service extends Model } /** - * ServiceStat hasMany relation. + * ServiceStat has many relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ @@ -129,7 +129,7 @@ class Service extends Model * * ! This is used to flush caching * - * @return array + * @return array */ protected function getCacheBaseTags(): array { diff --git a/app/Models/ServiceStat.php b/app/Models/ServiceStat.php index e3941bd..734b982 100644 --- a/app/Models/ServiceStat.php +++ b/app/Models/ServiceStat.php @@ -24,7 +24,7 @@ class ServiceStat extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'date', @@ -33,7 +33,7 @@ class ServiceStat extends Model /** * The model's attributes. * - * @var array + * @var array */ protected $attributes = [ 'nb_calls' => 0, @@ -42,7 +42,7 @@ class ServiceStat extends Model /** * Map attribute names to enum classes. * - * @var array + * @var array */ protected $casts = [ 'date' => 'date', @@ -51,7 +51,7 @@ class ServiceStat extends Model // * RELATIONS /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -61,7 +61,7 @@ class ServiceStat extends Model } /** - * Service BelongsTo relation. + * Service belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/SingleOptin.php b/app/Models/SingleOptin.php index dbd1e38..b9c95d0 100644 --- a/app/Models/SingleOptin.php +++ b/app/Models/SingleOptin.php @@ -44,7 +44,7 @@ class SingleOptin extends Model /** * The attributes that are mass assignable. * - * @var string[] + * @var array */ protected $fillable = [ 'email', @@ -65,7 +65,7 @@ class SingleOptin extends Model // * RELATIONS /** - * Brand BelongsTo relation. + * Brand belongs to relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/User.php b/app/Models/User.php index b0981f5..1e40a87 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -55,7 +55,7 @@ class User extends Authenticatable /** * The attributes that should be cast. * - * @var array + * @var array */ protected $casts = [ 'role' => RoleEnum::class, @@ -112,4 +112,14 @@ class User extends Authenticatable AuthorizationException::class ); } + + /** + * Brands many to many relation. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function brands(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + { + return $this->belongsToMany(Brand::class, 'brand_users'); + } } diff --git a/app/Traits/Models/MiniCrudModel.php b/app/Traits/Models/MiniCrudModel.php index 09109f1..c5058ed 100644 --- a/app/Traits/Models/MiniCrudModel.php +++ b/app/Traits/Models/MiniCrudModel.php @@ -3,8 +3,8 @@ namespace App\Traits\Models; use App\Enums\InputType; -use App\Lib\Helpers\FileStorageHelper; use App\Lib\Helpers\ToolboxHelper; +use Uwil\LaravelCommon\Helpers\FileHelper; trait MiniCrudModel { @@ -38,7 +38,7 @@ trait MiniCrudModel switch ($input['inputType']) { case InputType::text->value: $input['text'] = clean($input['text']); - $input['text'] = FileStorageHelper::storeModelFilesFromHtml($this, $input['text']); + $input['text'] = FileHelper::storeModelFilesFromHtml($this, $input['text']); break; } //end switch } //end foreach @@ -67,7 +67,7 @@ trait MiniCrudModel switch ($input['inputType']) { case InputType::text->value: $original = ToolboxHelper::getOriginal($this, 'data'); - FileStorageHelper::removeOldModelFilesFromHtml( + FileHelper::removeOldModelFilesFromHtml( $input['text'], $original[$index]['text'] ?? '' ); @@ -87,7 +87,7 @@ trait MiniCrudModel foreach ($this->data as $input) { switch ($input['inputType']) { case InputType::text->value: - FileStorageHelper::removeModelFilesOfHtml($input['text']); + FileHelper::removeModelFilesOfHtml($input['text']); break; } //end switch } //end foreach @@ -151,7 +151,7 @@ trait MiniCrudModel $data[$o]['value'] = \preg_replace( '/^\/|^/', '', - FileStorageHelper::storeFile($this, $input['value'], true) + FileHelper::storeFile($this, $input['value'], true) ); break; case InputType::selectEnum->value: diff --git a/composer.json b/composer.json index 566b56a..ab9afc3 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,8 @@ "rennokki/laravel-eloquent-query-cache": "^3.5", "sentry/sentry-laravel": "^4.10", "uwil/admin-secure-laravel": "^3.0", - "uwil/k8s-laravel": "^1.4" + "uwil/k8s-laravel": "^1.4", + "uwil/laravel-common": "^3.4" }, "require-dev": { "brianium/paratest": "^7.2", diff --git a/composer.lock b/composer.lock index b412990..ae05dc9 100644 --- a/composer.lock +++ b/composer.lock @@ -1964,6 +1964,150 @@ ], "time": "2023-12-03T19:50:20+00:00" }, + { + "name": "intervention/gif", + "version": "4.2.2", + "source": { + "type": "git", + "url": "https://github.com/Intervention/gif.git", + "reference": "5999eac6a39aa760fb803bc809e8909ee67b451a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/gif/zipball/5999eac6a39aa760fb803bc809e8909ee67b451a", + "reference": "5999eac6a39aa760fb803bc809e8909ee67b451a", + "shasum": "" + }, + "require": { + "php": "^8.1" + }, + "require-dev": { + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^10.0 || ^11.0 || ^12.0", + "slevomat/coding-standard": "~8.0", + "squizlabs/php_codesniffer": "^3.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Intervention\\Gif\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" + } + ], + "description": "Native PHP GIF Encoder/Decoder", + "homepage": "https://github.com/intervention/gif", + "keywords": [ + "animation", + "gd", + "gif", + "image" + ], + "support": { + "issues": "https://github.com/Intervention/gif/issues", + "source": "https://github.com/Intervention/gif/tree/4.2.2" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + }, + { + "url": "https://ko-fi.com/interventionphp", + "type": "ko_fi" + } + ], + "time": "2025-03-29T07:46:21+00:00" + }, + { + "name": "intervention/image", + "version": "3.11.3", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "d0f097b8a3fa8fb758efc9440b513aa3833cda17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/d0f097b8a3fa8fb758efc9440b513aa3833cda17", + "reference": "d0f097b8a3fa8fb758efc9440b513aa3833cda17", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "intervention/gif": "^4.2", + "php": "^8.1" + }, + "require-dev": { + "mockery/mockery": "^1.6", + "phpstan/phpstan": "^2.1", + "phpunit/phpunit": "^10.0 || ^11.0 || ^12.0", + "slevomat/coding-standard": "~8.0", + "squizlabs/php_codesniffer": "^3.8" + }, + "suggest": { + "ext-exif": "Recommended to be able to read EXIF data properly." + }, + "type": "library", + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@intervention.io", + "homepage": "https://intervention.io/" + } + ], + "description": "PHP image manipulation", + "homepage": "https://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "resize", + "thumbnail", + "watermark" + ], + "support": { + "issues": "https://github.com/Intervention/image/issues", + "source": "https://github.com/Intervention/image/tree/3.11.3" + }, + "funding": [ + { + "url": "https://paypal.me/interventionio", + "type": "custom" + }, + { + "url": "https://github.com/Intervention", + "type": "github" + }, + { + "url": "https://ko-fi.com/interventionphp", + "type": "ko_fi" + } + ], + "time": "2025-05-22T17:26:23+00:00" + }, { "name": "jean85/pretty-package-versions", "version": "2.1.0", @@ -2023,6 +2167,68 @@ }, "time": "2024-11-18T16:19:46+00:00" }, + { + "name": "kwaadpepper/image-resizer", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/Kwaadpepper/image-resizer.git", + "reference": "e0747fddc4e31ce57bda9db735060e279ae01780" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Kwaadpepper/image-resizer/zipball/e0747fddc4e31ce57bda9db735060e279ae01780", + "reference": "e0747fddc4e31ce57bda9db735060e279ae01780", + "shasum": "" + }, + "require": { + "illuminate/support": "~11|~12", + "intervention/image": "^3.6", + "laravel/framework": "~11|~12", + "php": "^8.2" + }, + "require-dev": { + "larastan/larastan": "^2.0", + "orchestra/testbench": "^9.0", + "slevomat/coding-standard": "^8.11" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Kwaadpepper\\ImageResizer\\ImageResizerServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Kwaadpepper\\ImageResizer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jérémy Munsch", + "email": "github@jeremydev.ovh", + "homepage": "https://jeremydev.ovh" + } + ], + "description": "Resize images on the fly and cache them", + "homepage": "https://github.com/kwaadpepper/image-resizer", + "keywords": [ + "images", + "laravel", + "resize" + ], + "support": { + "issues": "https://github.com/Kwaadpepper/image-resizer/issues", + "source": "https://github.com/Kwaadpepper/image-resizer/tree/3.1.0" + }, + "time": "2025-03-02T07:22:50+00:00" + }, { "name": "laravel/framework", "version": "v11.37.0", @@ -7717,6 +7923,70 @@ ], "description": "Laravel requirements for k8s" }, + { + "name": "uwil/laravel-common", + "version": "3.4.2", + "source": { + "type": "git", + "url": "git@lab.s-web.fr:ldc-web/projets/laravel-common.git", + "reference": "5959b1ae8aaaf118e5d1e1f34be8188ca41bcc42" + }, + "dist": { + "type": "zip", + "url": "https://lab.s-web.fr/api/v4/projects/215/packages/composer/archives/uwil/laravel-common.zip?sha=5959b1ae8aaaf118e5d1e1f34be8188ca41bcc42", + "reference": "5959b1ae8aaaf118e5d1e1f34be8188ca41bcc42", + "shasum": "" + }, + "require": { + "illuminate/support": "~11|~12", + "kwaadpepper/image-resizer": "^3.0", + "laravel/framework": "~11|~12", + "mews/purifier": "^3.4", + "php": "~8.3", + "sentry/sentry-laravel": "^4.10" + }, + "require-dev": { + "larastan/larastan": "^2.9", + "orchestra/testbench": "^9.0", + "phpunit/php-code-coverage": "^11.0", + "phpunit/phpunit": "^11.0", + "slevomat/coding-standard": "^8.3", + "squizlabs/php_codesniffer": "^3.7" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Uwil\\LaravelCommon\\CommonServiceProvider" + ] + } + }, + "autoload": { + "files": [ + "src/Helpers/methods.php" + ], + "psr-4": { + "Uwil\\LaravelCommon\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Uwil\\LaravelCommon\\Tests\\": "tests" + } + }, + "scripts": { + "test": [ + "vendor/bin/phpunit" + ], + "post-autoload-dump": [ + "@php ./vendor/bin/testbench package:discover --ansi" + ] + }, + "license": [ + "MIT" + ], + "description": "UWIL Laravel common utils" + }, { "name": "vlucas/phpdotenv", "version": "v5.6.1", diff --git a/database/factories/AnswerFactory.php b/database/factories/AnswerFactory.php index 2d810c0..dab69be 100644 --- a/database/factories/AnswerFactory.php +++ b/database/factories/AnswerFactory.php @@ -19,7 +19,7 @@ class AnswerFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { return [ 'answer' => $this->faker->realText(20), diff --git a/database/factories/BrandFactory.php b/database/factories/BrandFactory.php index 777ac2b..b005079 100644 --- a/database/factories/BrandFactory.php +++ b/database/factories/BrandFactory.php @@ -19,10 +19,13 @@ class BrandFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { return [ - 'name' => $this->faker->company, + 'name' => $this->faker->company, + 'url' => $this->faker->url, + 'url_claim' => $this->faker->url, + 'domain' => $this->faker->domainName, ]; } } diff --git a/database/factories/ClaimFactory.php b/database/factories/ClaimFactory.php new file mode 100644 index 0000000..e46c9e8 --- /dev/null +++ b/database/factories/ClaimFactory.php @@ -0,0 +1,44 @@ + $this->faker->firstName(), + 'last_name' => $this->faker->lastName(), + 'email' => $this->faker->email(), + 'address' => $this->faker->optional()->address(), + 'city' => $this->faker->optional()->city(), + 'postcode' => $this->faker->optional()->postcode(), + 'message' => $this->faker->sentence(10), + 'type' => collect(ClaimType::toArray())->random()->value, + 'status' => collect(ClaimStatus::toArray())->random()->value, + 'brand_id' => $this->faker->randomElement(Brand::pluck('id')), + 'subject_id' => $this->faker->randomElement(ClaimSubject::pluck('id')), + 'customer_id' => $this->faker->boolean(50) ? $this->faker->randomElement(Customer::pluck('id')) : null, + ]; + } +} diff --git a/database/factories/ClaimMailTemplateFactory.php b/database/factories/ClaimMailTemplateFactory.php new file mode 100644 index 0000000..131a395 --- /dev/null +++ b/database/factories/ClaimMailTemplateFactory.php @@ -0,0 +1,31 @@ + $this->faker->word(), + 'content' => $this->faker->sentence(10), + 'brand_id' => $this->faker->randomElement(Brand::pluck('id')), + ]; + } +} diff --git a/database/factories/ClaimMessageFactory.php b/database/factories/ClaimMessageFactory.php new file mode 100644 index 0000000..f6fd58c --- /dev/null +++ b/database/factories/ClaimMessageFactory.php @@ -0,0 +1,34 @@ + $this->faker->sentence(10), + 'type' => collect(ClaimMessageType::toArray())->random()->value, + 'claim_id' => $this->faker->randomElement(Claim::pluck('id')), + 'user_id' => $this->faker->boolean(50) ? $this->faker->randomElement(User::pluck('id')) : null, + ]; + } +} diff --git a/database/factories/ClaimSubjectFactory.php b/database/factories/ClaimSubjectFactory.php new file mode 100644 index 0000000..5282a82 --- /dev/null +++ b/database/factories/ClaimSubjectFactory.php @@ -0,0 +1,30 @@ + $this->faker->word(), + 'brand_id' => $this->faker->randomElement(Brand::pluck('id')), + ]; + } +} diff --git a/database/factories/CustomerFactory.php b/database/factories/CustomerFactory.php index be9fad3..80dadc2 100644 --- a/database/factories/CustomerFactory.php +++ b/database/factories/CustomerFactory.php @@ -19,7 +19,7 @@ class CustomerFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { return [ 'email' => preg_replace( diff --git a/database/factories/CustomerInfoFactory.php b/database/factories/CustomerInfoFactory.php index 6aadcaa..919ac10 100644 --- a/database/factories/CustomerInfoFactory.php +++ b/database/factories/CustomerInfoFactory.php @@ -22,7 +22,7 @@ class CustomerInfoFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { $faker = \Faker\Factory::create('fr_FR'); $faker->addProvider(new \Faker\Provider\fr_FR\Address($faker)); @@ -36,17 +36,17 @@ class CustomerInfoFactory extends Factory $phone = '0388982532'; } return [ - 'firstname' => $faker->firstName, - 'lastname' => $faker->lastName, + 'firstname' => $faker->firstName, + 'lastname' => $faker->lastName, 'birth_date' => $faker->dateTimeBetween('-60 years', '-18 years'), - 'address' => $faker->address, - 'address2' => '', - 'phone' => $phone, - 'country' => $country->value, - 'city' => $faker->city, - 'postcode' => $faker->postcode, - 'opt_in' => $faker->boolean, - 'hashcode' => $faker->sha1 + 'address' => $faker->address, + 'address2' => '', + 'phone' => $phone, + 'country' => $country->value, + 'city' => $faker->city, + 'postcode' => $faker->postcode, + 'opt_in' => $faker->boolean, + 'hashcode' => $faker->sha1 ]; } } diff --git a/database/factories/CustomerLoginFactory.php b/database/factories/CustomerLoginFactory.php index b1b3dd9..7d4c3c9 100644 --- a/database/factories/CustomerLoginFactory.php +++ b/database/factories/CustomerLoginFactory.php @@ -27,7 +27,7 @@ class CustomerLoginFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { $bool = $this->faker->boolean; // * Force first to be active. @@ -36,9 +36,9 @@ class CustomerLoginFactory extends Factory $bool = false; } return [ - 'password' => 'testPassword', + 'password' => 'testPassword', 'last_connection' => Carbon::now(), - 'status' => $bool + 'status' => $bool ]; } } diff --git a/database/factories/QuestionFactory.php b/database/factories/QuestionFactory.php index d86a99d..ff13112 100644 --- a/database/factories/QuestionFactory.php +++ b/database/factories/QuestionFactory.php @@ -24,7 +24,7 @@ class QuestionFactory extends Factory { return [ 'question' => $this->faker->realText(40), - 'type' => collect(QuestionType::toArray())->random()->value, + 'type' => collect(QuestionType::toArray())->random()->value, ]; } } diff --git a/database/factories/ServiceFactory.php b/database/factories/ServiceFactory.php index 00a3a8f..7ccb571 100644 --- a/database/factories/ServiceFactory.php +++ b/database/factories/ServiceFactory.php @@ -19,7 +19,7 @@ class ServiceFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { return [ 'name' => $this->faker->lexify('?????????') diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 46cb311..d6ebccc 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -13,13 +13,13 @@ class UserFactory extends Factory * * @return array */ - public function definition() + public function definition(): array { $published = $this->faker->boolean(75); return [ - 'first_name' => fake()->firstname(), - 'last_name' => fake()->lastname(), - 'email' => fake()->unique()->safeEmail(), + 'first_name' => $this->faker->firstname(), + 'last_name' => $this->faker->lastname(), + 'email' => $this->faker->unique()->safeEmail(), 'email_verified_at' => now(), 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'remember_token' => Str::random(10), diff --git a/database/factories/assets/brands/default-logo-550x550.jpg b/database/factories/assets/brands/default-logo-550x550.jpg new file mode 100644 index 0000000000000000000000000000000000000000..00854b07b82f1ca51d2b24ce0c19e02c3db2422b GIT binary patch literal 7105 zcmeH`c{tSj9>>39Hp?JFL&I1`G*L`rE5q2vQnEA%bv4v6l;e)IM$VuGbHgFB+_F!W zsKijoQOK4(qe3c6G_;pg%v{d7xAQ#ruY2#)U-y~s@A>?GfBe4B=lQ00aU6Wc2~UF<=A45eOs#E{;SZB_zZpQ3}#1DJhh){CZghRTZq7stN|9j@zoE zuBoSm!RVT7)-y095{XzHGm+nARpp84JhbGIv(>PxK?LGqgRD*T(W98Rh3PO$Yx`;8k z$+HZME39BF>gjm)d+d~#{uOsV)({Hsvj|T7hQBX3CInL*%fW31_MvK>*}=1>eRN2+ z7vphpU3^kNoKofY_FfOMgjV!|#Ig{qctl2ACbL!a>dkhpMdkOe?mqat0|s-H;Ico1 zRi2OMh=hpLg z9Qpnn9a>O#`@Fc%mSdkCdNUaL7Fim@q0bK?S9?`+gmPQcyLD`7tnks#_f+@ z^R;zU*1H=PG(~NS@3?StF=EV@Vf$;L!!SOzCF7X9gnVBx;a=l#}s^dxjYADmhwjq@~dcTT_7c(mex#{p|yPA!Z0 zN|LZ~U;q}K{ZhIx!x&zQ)mh?&Z0cDZjNua8%IbGVPd)Yg3tZN9|7&BiQLRzc2K0vjl>INCG%JfwyNad8xgs!3?l8eW za(rh(qw~>L!hYN9l(0)h!|IN&aN~#>_wHCjYJ`bto<%Fn6&_+uTdCZ4w(1ayIawNF zq%;-( zNtF)W<}zGDw+-(~-msMOX*u{_J10a^9_PLBdPT2|MGEY!kFnvoM=16oCWcmv>uDW8 zxx!SaE~NSW&33q1UW)gK`O=^^+uj3XJfii|$FMz}B5x#FQm9Z>$@hrEA5$NIZzMS> z)7bD>Ai1@Zf|wwGF6RttMr|@vCM9)p{$_U?t&9sI)x?wK==BRy z;|9-CF29*~;|~%|lEW^_$i&_YsXXOc37~Os<9!+Qo-p0Rq!i$F(!D; z*#`jf!E6kF<5Zx9&`yvrnT+Y2)^5`7O)Zx6M32EPk?msYTH zm08P~h%LtI_rF>9OTb9o7Ndx(`1$@bu{mZ^4VH;MV5pd_3&naKNz!o)IB%DdNbXQp z43l;mrQZ!w+<2>|9p96V8_Y~!o9v&uirRe*d%8*DyI>7c)RB&{S0|bT%zy{x0_yx_hbsdTNUai?;#wiNmL0u(0>cbh zYYq3_&u6kvAp@-zntCHh2z*oZ1!K1D!Rb!{!@M7-?~fV-Q6JHrh#U|(AaX$DfXD%n L13$_E;p2Y*Mq52W literal 0 HcmV?d00001 diff --git a/database/migrations/2025_07_24_091926_add_fields_to_brands_table.php b/database/migrations/2025_07_24_091926_add_fields_to_brands_table.php new file mode 100644 index 0000000..a53c76d --- /dev/null +++ b/database/migrations/2025_07_24_091926_add_fields_to_brands_table.php @@ -0,0 +1,44 @@ +id()->comment('Brand id.')->change(); + $table->string('name')->comment('Brand name.')->change(); + $table->string('logo')->comment('Brand logo.')->after('name'); + $table->string('url')->comment('Brand url link.')->after('logo'); + $table->string('url_claim')->comment('Brand associative url claim.')->after('url'); + $table->string('domain')->comment('Brand domain.')->after('url_claim'); + $table->timestamp('created_at')->nullable()->comment('Brand created date.')->change(); + $table->timestamp('updated_at')->nullable()->comment('Brand updated date.')->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::table('brands', function (Blueprint $table) { + $table->id()->change(); + $table->string('name')->change(); + $table->dropColumn('logo'); + $table->dropColumn('url'); + $table->dropColumn('url_claim'); + $table->dropColumn('domain'); + }); + } +}; diff --git a/database/migrations/2025_07_24_092956_create_brand_users_pivot_table.php b/database/migrations/2025_07_24_092956_create_brand_users_pivot_table.php new file mode 100644 index 0000000..d4cdd46 --- /dev/null +++ b/database/migrations/2025_07_24_092956_create_brand_users_pivot_table.php @@ -0,0 +1,33 @@ +foreignId('brand_id')->comment('Brand associated.')->constrained('brands') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreignId('user_id')->comment('User associated.')->constrained('users') + ->onUpdate('cascade')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('brand_users'); + } +}; diff --git a/database/migrations/2025_07_24_102413_create_claim_mail_templates_table.php b/database/migrations/2025_07_24_102413_create_claim_mail_templates_table.php new file mode 100644 index 0000000..8ddd786 --- /dev/null +++ b/database/migrations/2025_07_24_102413_create_claim_mail_templates_table.php @@ -0,0 +1,36 @@ +id()->comment('Mail template id.'); + $table->string('label')->comment('Mail template label.'); + $table->text('content')->comment('Mail template content.'); + $table->foreignId('brand_id')->comment('Mail template associated Brand.')->constrained('brands') + ->onUpdate('cascade')->onDelete('cascade'); + $table->timestamp('created_at')->nullable()->comment('Mail template created date.'); + $table->timestamp('updated_at')->nullable()->comment('Mail template updated date.'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('claim_mail_templates'); + } +}; diff --git a/database/migrations/2025_07_24_110652_create_claim_subjects_table.php b/database/migrations/2025_07_24_110652_create_claim_subjects_table.php new file mode 100644 index 0000000..466903e --- /dev/null +++ b/database/migrations/2025_07_24_110652_create_claim_subjects_table.php @@ -0,0 +1,35 @@ +id()->comment('Subject id.'); + $table->string('label')->comment('Subject label.'); + $table->foreignId('brand_id')->comment('Subject associated Brand.')->constrained('brands') + ->onUpdate('cascade')->onDelete('cascade'); + $table->timestamp('created_at')->nullable()->comment('Subject created date.'); + $table->timestamp('updated_at')->nullable()->comment('Subject updated date.'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('claim_subjects'); + } +}; diff --git a/database/migrations/2025_07_24_113251_create_claims_table.php b/database/migrations/2025_07_24_113251_create_claims_table.php new file mode 100644 index 0000000..21193d8 --- /dev/null +++ b/database/migrations/2025_07_24_113251_create_claims_table.php @@ -0,0 +1,53 @@ +id()->comment('Claim id.'); + $table->string('reference')->nullable()->default(null)->comment('Claim reference.'); + $table->string('first_name')->comment('Claimant\'s first name.'); + $table->string('last_name')->comment('Claimant\'s last name.'); + $table->string('email')->comment('Claimant\'s email.'); + $table->string('address')->nullable()->comment('Claimant\'s address.'); + $table->string('city')->nullable()->comment('Claimant\'s city.'); + $table->string('postcode')->nullable()->comment('Claimant\'s postcode.'); + $table->string('file')->nullable()->comment('Claimant\'s file.'); + $table->text('message')->comment('Claimant\'s message.'); + $table->unsignedTinyInteger('type')->default(ClaimType::classic) + ->comment('Claim type (ClaimType enum).'); + $table->unsignedTinyInteger('status')->default(ClaimStatus::untreated) + ->comment('Claim status (ClaimStatus enum).'); + $table->foreignId('brand_id')->comment('Claim associated Brand.')->constrained('brands') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreignId('subject_id')->comment('Claim associated Subject.')->constrained('claim_subjects') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreignId('customer_id')->nullable()->comment('Claim associated Customer.') + ->constrained('customers')->onUpdate('cascade')->onDelete('set null'); + $table->timestamp('created_at')->nullable()->comment('Claim created date.'); + $table->timestamp('updated_at')->nullable()->comment('Claim updated date.'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('claims'); + } +}; diff --git a/database/migrations/2025_07_24_122149_claim_messages_table.php b/database/migrations/2025_07_24_122149_claim_messages_table.php new file mode 100644 index 0000000..30ac48e --- /dev/null +++ b/database/migrations/2025_07_24_122149_claim_messages_table.php @@ -0,0 +1,38 @@ +id()->comment('Message id.'); + $table->text('content')->comment('Message content.'); + $table->unsignedTinyInteger('type')->comment('Message type (MessageType enum).'); + $table->foreignId('claim_id')->comment('Message associated Claim.')->constrained('claims') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreignId('user_id')->nullable()->comment('Message associated User.')->constrained('users') + ->onUpdate('cascade')->onDelete('cascade'); + $table->timestamp('created_at')->nullable()->comment('Message created date.'); + $table->timestamp('updated_at')->nullable()->comment('Message updated date.'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down(): void + { + Schema::dropIfExists('claim_messages'); + } +}; diff --git a/database/seeders/BrandSeeder.php b/database/seeders/BrandSeeder.php index 0012ec6..7b6958c 100644 --- a/database/seeders/BrandSeeder.php +++ b/database/seeders/BrandSeeder.php @@ -7,6 +7,7 @@ use App\Models\Brand; use App\Models\Question; use App\Models\Service; use Illuminate\Database\Seeder; +use Uwil\LaravelCommon\Helpers\FileHelper; class BrandSeeder extends Seeder { @@ -15,10 +16,17 @@ class BrandSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { /** @var \App\Models\Brand $brand */ - Brand::factory(10)->create()->each(function ($brand) { + Brand::factory(10)->make()->each(function ($brand) { + $brand->logo = FileHelper::storeFile( + $brand, + new \SplFileInfo( + \resource_path('../database/factories/assets/brands/default-logo-550x550.jpg') + ) + ); + $brand->saveOrFail(); Service::factory(1)->make()->each( /** @var \App\Models\Service $service*/ function ($service) use ($brand) { diff --git a/database/seeders/BrandStatSeeder.php b/database/seeders/BrandStatSeeder.php index d1d6a52..46be3e5 100644 --- a/database/seeders/BrandStatSeeder.php +++ b/database/seeders/BrandStatSeeder.php @@ -14,7 +14,7 @@ class BrandStatSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { BrandStat::truncate(); // * On génère 1 an pour chaque marque. @@ -36,13 +36,13 @@ class BrandStatSeeder extends Seeder $pOld = 1 - $pNew; $brandStat = new BrandStat([ - 'active' => \floor($total * $pActive), - 'inactive' => \ceil($total * $pInactive), - 'old_accounts' => \ceil($total * $pOld), - 'new_accounts' => \floor($total * $pNew), + 'active' => \floor($total * $pActive), + 'inactive' => \ceil($total * $pInactive), + 'old_accounts' => \ceil($total * $pOld), + 'new_accounts' => \floor($total * $pNew), 'total_accounts' => $total, // 15% optin - 'total_opt_in' => ceil($total * 0.15) + 'total_opt_in' => ceil($total * 0.15) ]); $brandStat->brand()->associate($brand); $brandStat->created_at = $startDay; diff --git a/database/seeders/ClaimMailTemplateSeeder.php b/database/seeders/ClaimMailTemplateSeeder.php new file mode 100644 index 0000000..ed283e6 --- /dev/null +++ b/database/seeders/ClaimMailTemplateSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/ClaimMessageSeeder.php b/database/seeders/ClaimMessageSeeder.php new file mode 100644 index 0000000..a99158f --- /dev/null +++ b/database/seeders/ClaimMessageSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/ClaimSeeder.php b/database/seeders/ClaimSeeder.php new file mode 100644 index 0000000..139d6c6 --- /dev/null +++ b/database/seeders/ClaimSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/ClaimSubjectSeeder.php b/database/seeders/ClaimSubjectSeeder.php new file mode 100644 index 0000000..cf7b460 --- /dev/null +++ b/database/seeders/ClaimSubjectSeeder.php @@ -0,0 +1,19 @@ +create(); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 68ec9ee..82a52e1 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -11,7 +11,7 @@ class DatabaseSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { $this->call([ BrandSeeder::class, @@ -19,6 +19,10 @@ class DatabaseSeeder extends Seeder BrandStatSeeder::class, UserSeeder::class, SingleOptinSeeder::class, + ClaimMailTemplateSeeder::class, + ClaimSubjectSeeder::class, + ClaimSeeder::class, + ClaimMessageSeeder::class, ]); } } diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index ba66561..8019b31 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -2,6 +2,7 @@ namespace Database\Seeders; +use App\Models\Brand; use App\Models\User; use Illuminate\Database\Seeder; @@ -12,8 +13,11 @@ class UserSeeder extends Seeder * * @return void */ - public function run() + public function run(): void { - User::factory(20)->create(); + User::factory(20)->create()->each(function ($user) { + $brands = Brand::inRandomOrder()->take(rand(1, 3))->pluck('id'); + $user->brands()->attach($brands); + }); } }