From 8476ac303e045ee7800db3f635444de28b0a89c9 Mon Sep 17 00:00:00 2001 From: Nicolas Demangeat Date: Thu, 21 Sep 2023 10:41:03 +0200 Subject: [PATCH 1/8] bugs fix --- .../views/bo/pages/brands/create.blade.php | 55 ++++++----- .../views/bo/pages/brands/edit.blade.php | 60 ++++++------ .../bo/pages/brands/index-list.blade.php | 92 ++++++++++--------- 3 files changed, 112 insertions(+), 95 deletions(-) diff --git a/resources/views/bo/pages/brands/create.blade.php b/resources/views/bo/pages/brands/create.blade.php index 1d4e211..623a1a3 100644 --- a/resources/views/bo/pages/brands/create.blade.php +++ b/resources/views/bo/pages/brands/create.blade.php @@ -1,36 +1,41 @@ @extends('bo.layout') @section('title', sprintf('%s - %s', Str::singular(__('models.classes.brands')), Str::ucfirst(__('create')))) -@section('description', __('Creation of a new brand.')) +@section('description', __('Création d\'une nouvelle marque.')) -@section('breadcrumb', request()->route()->getName()) +@section('breadcrumb', + request()->route()->getName()) @section('content') -
-
-
-
-

- - - - {{ Str::singular(__('models.classes.brands')) }} {{ __('create') }} -

-
-
-
-
-
- @csrf - @include('bo.pages.brands.form-inputs') +
+
-
- +
+

+ + + + {{ Str::singular(__('models.classes.brands')) }} {{ __('create') }} +

- +
+
+
+ @csrf + @include('bo.pages.brands.form-inputs') +
+
+ +
+
+
+
-
@endsection diff --git a/resources/views/bo/pages/brands/edit.blade.php b/resources/views/bo/pages/brands/edit.blade.php index 9dec8b5..84d803d 100644 --- a/resources/views/bo/pages/brands/edit.blade.php +++ b/resources/views/bo/pages/brands/edit.blade.php @@ -1,37 +1,43 @@ @extends('bo.layout', ['brParam' => $brandModel]) -@section('title', sprintf('%s - %s %s', Str::singular(__('models.classes.brands')), Str::ucfirst(__('crud.actions.edit')), $brandModel->seo_title)) -@section('description', $brandModel->seo_description) +@section('title', sprintf('%s - %s %s', Str::singular(__('models.classes.brands')), Str::ucfirst(__('crud.actions.edit')), + $brandModel->name)) +@section('description', __('crud.actions.edit')) -@section('breadcrumb', request()->route()->getName()) +@section('breadcrumb', + request()->route()->getName()) @section('content') -
-
-
-
-

- - - - {{ Str::singular(__('models.classes.brands')) }} {{ __('crud.actions.edit') }} -

-
-
-
-
-
- @csrf - @method('PUT') - @include('bo.pages.brands.form-inputs', ['model' => $brandModel]) +
+
-
- +
+

+ + + + {{ Str::singular(__('models.classes.brands')) }} {{ __('crud.actions.edit') }} +

- +
+
+
+ @csrf + @method('PUT') + @include('bo.pages.brands.form-inputs', ['model' => $brandModel]) +
+
+ +
+
+
+
-
@endsection diff --git a/resources/views/bo/pages/brands/index-list.blade.php b/resources/views/bo/pages/brands/index-list.blade.php index bddb92a..26466ad 100644 --- a/resources/views/bo/pages/brands/index-list.blade.php +++ b/resources/views/bo/pages/brands/index-list.blade.php @@ -1,53 +1,59 @@
- +
@php - $cols = [ - 'name' => __('validation.attributes.name'), - 'contact_mail' => __('validation.attributes.contact_mail'), - 'rcs' => __('validation.attributes.rcs'), - 'logo' => __('validation.attributes.logo'), - 'crm_token' => __('validation.attributes.crm_token'), - 'crm_password' => __('validation.attributes.crm_password'), - 'updated_at' => __('validation.attributes.updated_at')]; + $cols = [ + 'name' => __('validation.attributes.name'), + 'contact_mail' => __('validation.attributes.contact_mail'), + 'rcs' => __('validation.attributes.rcs'), + 'logo' => __('validation.attributes.logo'), + 'crm_token' => __('validation.attributes.crm_token'), + 'crm_password' => __('validation.attributes.crm_password'), + 'updated_at' => __('validation.attributes.updated_at'), + ]; @endphp - @include('bo.modules.table-col-sorter', [ 'cols' => $cols, 'mobileHide' => ['status']]) + @include('bo.modules.table-col-sorter', ['cols' => $cols, 'mobileHide' => ['status']]) - @if($brandModels->count()) - @foreach ($brandModels as $brandModel) - - - - - - - - - - - @endforeach + @if ($brandModels->count()) + @foreach ($brandModels as $brandModel) + + + + + + + + + + + @endforeach @else - - - + + + @endif
{{ $brandModel->name }}{{ $brandModel->contact_mail }}{{ $brandModel->rcs }}{{ $brandModel->logo }}{{ $brandModel->crm_token }}{{ $brandModel->crm_password }} - {{ $brandModel->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }} - -
- - - - @method('DELETE') - @csrf -
- -
-
-
{{ $brandModel->name }}{{ $brandModel->contact_mail }}{{ $brandModel->rcs }}{{ $brandModel->logo }}{{ $brandModel->crm_token }}{{ $brandModel->crm_password }} + {{ $brandModel->updated_at->formatLocalized('%d/%m/%Y à %H:%M') }} + +
+ + + + @method('DELETE') + @csrf +
+ +
+
+
- {{ __('crud.helpers.no_results', ['models' => __('models.classes.brands') ])}} -
+ {{ __('crud.helpers.no_results', ['model' => __('models.classes.brands')]) }} +
From d91a81453a07ed5647198f890130d18f88b58f12 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 24 Nov 2023 15:05:07 +0100 Subject: [PATCH 2/8] Remove useless gitkeep --- app/Enums/.gitkeep | 0 app/Http/Requests/Bo/.gitkeep | 0 app/Traits/Requests/.gitkeep | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 app/Enums/.gitkeep delete mode 100644 app/Http/Requests/Bo/.gitkeep delete mode 100644 app/Traits/Requests/.gitkeep diff --git a/app/Enums/.gitkeep b/app/Enums/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/Http/Requests/Bo/.gitkeep b/app/Http/Requests/Bo/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/Traits/Requests/.gitkeep b/app/Traits/Requests/.gitkeep deleted file mode 100644 index e69de29..0000000 From 96034ae3c27b2131e61e8a861937766c96ab5175 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 24 Nov 2023 15:05:47 +0100 Subject: [PATCH 3/8] Update static files --- .env.example | 26 --------- README.md | 67 +--------------------- composer.json | 15 ++--- composer.lock | 152 +------------------------------------------------- 4 files changed, 7 insertions(+), 253 deletions(-) diff --git a/.env.example b/.env.example index b404d19..e19fb18 100644 --- a/.env.example +++ b/.env.example @@ -22,12 +22,6 @@ QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 -MEMCACHED_HOST=127.0.0.1 - -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - MAIL_MAILER=smtp MAIL_HOST=mailpit MAIL_PORT=1025 @@ -37,25 +31,5 @@ MAIL_ENCRYPTION=null MAIL_FROM_ADDRESS="hello@example.com" MAIL_FROM_NAME="${APP_NAME}" -AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= -AWS_DEFAULT_REGION=us-east-1 -AWS_BUCKET= -AWS_USE_PATH_STYLE_ENDPOINT=false - -PUSHER_APP_ID= -PUSHER_APP_KEY= -PUSHER_APP_SECRET= -PUSHER_HOST= -PUSHER_PORT=443 -PUSHER_SCHEME=https -PUSHER_APP_CLUSTER=mt1 - -VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -VITE_PUSHER_HOST="${PUSHER_HOST}" -VITE_PUSHER_PORT="${PUSHER_PORT}" -VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" -VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" - # Sentry SENTRY_LARAVEL_DSN= \ No newline at end of file diff --git a/README.md b/README.md index 3ed385a..7e0f87f 100644 --- a/README.md +++ b/README.md @@ -1,66 +1 @@ -

Laravel Logo

- -

-Build Status -Total Downloads -Latest Stable Version -License -

- -## About Laravel - -Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: - -- [Simple, fast routing engine](https://laravel.com/docs/routing). -- [Powerful dependency injection container](https://laravel.com/docs/container). -- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. -- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). -- Database agnostic [schema migrations](https://laravel.com/docs/migrations). -- [Robust background job processing](https://laravel.com/docs/queues). -- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). - -Laravel is accessible, powerful, and provides tools required for large, robust applications. - -## Learning Laravel - -Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. - -You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch. - -If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 2000 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. - -## Laravel Sponsors - -We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). - -### Premium Partners - -- **[Vehikl](https://vehikl.com/)** -- **[Tighten Co.](https://tighten.co)** -- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** -- **[64 Robots](https://64robots.com)** -- **[Cubet Techno Labs](https://cubettech.com)** -- **[Cyber-Duck](https://cyber-duck.co.uk)** -- **[Many](https://www.many.co.uk)** -- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** -- **[DevSquad](https://devsquad.com)** -- **[Curotec](https://www.curotec.com/services/technologies/laravel/)** -- **[OP.GG](https://op.gg)** -- **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)** -- **[Lendio](https://lendio.com)** - -## Contributing - -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). - -## Code of Conduct - -In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). - -## Security Vulnerabilities - -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. - -## License - -The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). +# MesBR \ No newline at end of file diff --git a/composer.json b/composer.json index 2b67634..6388b99 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { - "name": "laravel/laravel", + "name": "uwil/mesbr", "type": "project", - "description": "The Laravel Framework.", + "description": "BR management application.", "keywords": [ "framework", "laravel" @@ -20,15 +20,13 @@ "require-dev": { "fakerphp/faker": "^1.9.1", "kitloong/laravel-migrations-generator": "^6.8", - "krlove/eloquent-model-generator": "dev-l10-compatibility", "laravel/pint": "^1.0", "laravel/sail": "^1.18", "mockery/mockery": "^1.4.4", "nunomaduro/collision": "^7.0", "phpunit/phpunit": "^10.0", "slevomat/coding-standard": "^8.10", - "spatie/laravel-ignition": "^2.0", - "thedoctor0/laravel-factory-generator": "^1.2" + "spatie/laravel-ignition": "^2.0" }, "autoload": { "psr-4": { @@ -37,12 +35,7 @@ "Database\\Seeders\\": "database/seeders/" } }, - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/laravel-shift/eloquent-model-generator.git" - } - ], + "repositories": [], "autoload-dev": { "psr-4": { "Tests\\": "tests/" diff --git a/composer.lock b/composer.lock index 8b7f506..560ac1c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a7500b4c46c60cc929e9c3e85844d175", + "content-hash": "246d8cf8d2b528e7b07ee0ef3a355bdf", "packages": [ { "name": "brick/math", @@ -7582,90 +7582,6 @@ ], "time": "2023-03-26T07:37:00+00:00" }, - { - "name": "krlove/code-generator", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/krlove/code-generator.git", - "reference": "1ac521f5ef79a376282e3315ba6a13a83c63fb9a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/krlove/code-generator/zipball/1ac521f5ef79a376282e3315ba6a13a83c63fb9a", - "reference": "1ac521f5ef79a376282e3315ba6a13a83c63fb9a", - "shasum": "" - }, - "type": "library", - "autoload": { - "psr-4": { - "Krlove\\CodeGenerator\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Code Generator", - "support": { - "issues": "https://github.com/krlove/code-generator/issues", - "source": "https://github.com/krlove/code-generator/tree/1.0.1" - }, - "time": "2022-02-20T12:24:22+00:00" - }, - { - "name": "krlove/eloquent-model-generator", - "version": "dev-l10-compatibility", - "source": { - "type": "git", - "url": "https://github.com/laravel-shift/eloquent-model-generator.git", - "reference": "d8f0280de04d85cf2991e5a5dd317f5dea239d95" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laravel-shift/eloquent-model-generator/zipball/d8f0280de04d85cf2991e5a5dd317f5dea239d95", - "reference": "d8f0280de04d85cf2991e5a5dd317f5dea239d95", - "shasum": "" - }, - "require": { - "doctrine/dbal": "^3.5", - "illuminate/config": "^10.0", - "illuminate/console": "^10.0", - "illuminate/database": "^10.0", - "illuminate/support": "^10.0", - "krlove/code-generator": "^1.0", - "php": "^8.1" - }, - "require-dev": { - "phpunit/phpunit": "^9.5.10" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "Krlove\\EloquentModelGenerator\\Provider\\GeneratorServiceProvider" - ] - } - }, - "autoload": { - "psr-4": { - "Krlove\\EloquentModelGenerator\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Krlove\\Tests\\Integration\\": "tests/integration" - } - }, - "license": [ - "MIT" - ], - "description": "Eloquent Model Generator", - "support": { - "source": "https://github.com/laravel-shift/eloquent-model-generator/tree/l10-compatibility" - }, - "time": "2023-01-30T20:15:06+00:00" - }, { "name": "laravel/pint", "version": "v1.8.0", @@ -10124,68 +10040,6 @@ ], "time": "2023-02-16T09:57:23+00:00" }, - { - "name": "thedoctor0/laravel-factory-generator", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/TheDoctor0/laravel-factory-generator.git", - "reference": "890d2b8bac282e7595db747e77daff3ff9b871ec" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/TheDoctor0/laravel-factory-generator/zipball/890d2b8bac282e7595db747e77daff3ff9b871ec", - "reference": "890d2b8bac282e7595db747e77daff3ff9b871ec", - "shasum": "" - }, - "require": { - "doctrine/dbal": "^2.9|^2.10|^3.0", - "illuminate/console": "^8.0|^9.0|^10.0", - "illuminate/filesystem": "^8.0|^9.0|^10.0", - "illuminate/support": "^8.0|^9.0|^10.0", - "php": ">=7.4" - }, - "type": "library", - "extra": { - "laravel": { - "providers": [ - "TheDoctor0\\LaravelFactoryGenerator\\FactoryGeneratorServiceProvider" - ] - } - }, - "autoload": { - "psr-4": { - "TheDoctor0\\LaravelFactoryGenerator\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Automatically generate Laravel factories for your models.", - "keywords": [ - "factories", - "factory", - "generator", - "laravel", - "tests" - ], - "support": { - "issues": "https://github.com/TheDoctor0/laravel-factory-generator/issues", - "source": "https://github.com/TheDoctor0/laravel-factory-generator/tree/1.3.0" - }, - "funding": [ - { - "url": "https://www.paypal.me/thedoctor0", - "type": "custom" - }, - { - "url": "https://github.com/thedoctor0", - "type": "github" - } - ], - "time": "2023-03-08T18:25:21+00:00" - }, { "name": "theseer/tokenizer", "version": "1.2.1", @@ -10239,9 +10093,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "krlove/eloquent-model-generator": 20 - }, + "stability-flags": [], "prefer-stable": true, "prefer-lowest": false, "platform": { From 0a09a36b953c9ce446b58eb681b518fb40000ef6 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 24 Nov 2023 15:06:15 +0100 Subject: [PATCH 4/8] Force require PHP8.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6388b99..9de6276 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ ], "license": "MIT", "require": { - "php": "^8.1", + "php": "^8.2", "diglactic/laravel-breadcrumbs": "^8.0", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^10.0", From 80dbb04671880fe2ff7a176bfbd83beed63daab1 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 24 Nov 2023 15:35:08 +0100 Subject: [PATCH 5/8] PHPCS --- app/Http/Controllers/Bo/BrandController.php | 1 - app/Models/Basket.php | 14 +++++- app/Models/BasketsContent.php | 14 +++++- app/Models/Brand.php | 56 ++++++--------------- app/Models/Campaign.php | 17 ++++++- app/Models/Coupon.php | 42 +++++++++++----- app/Models/CouponLog.php | 5 ++ app/Models/Customer.php | 5 ++ 8 files changed, 95 insertions(+), 59 deletions(-) diff --git a/app/Http/Controllers/Bo/BrandController.php b/app/Http/Controllers/Bo/BrandController.php index 8568d21..98cf714 100644 --- a/app/Http/Controllers/Bo/BrandController.php +++ b/app/Http/Controllers/Bo/BrandController.php @@ -10,7 +10,6 @@ use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; - class BrandController extends Controller { /** diff --git a/app/Models/Basket.php b/app/Models/Basket.php index 50ec75a..86b7c7a 100644 --- a/app/Models/Basket.php +++ b/app/Models/Basket.php @@ -11,19 +11,31 @@ class Basket extends Model { use HasFactory; + /** + * Fillable + * + * @var string[] + */ protected $fillable = [ 'reference', 'customer_id', 'campaign_id' ]; - public function content() : HasMany + /** + * Get the content owned by the Basket + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + public function content(): HasMany { return $this->hasMany(BasketsContent::class); } /** * The "booted" method of the model. + * + * @return void */ protected static function booted(): void { diff --git a/app/Models/BasketsContent.php b/app/Models/BasketsContent.php index 400ff5c..673e683 100644 --- a/app/Models/BasketsContent.php +++ b/app/Models/BasketsContent.php @@ -10,12 +10,22 @@ class BasketsContent extends Model { use HasFactory; - public function basket() : BelongsTo + /** + * Get the basket that owns the BasketContent + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function basket(): BelongsTo { return $this->belongsTo(Basket::class); } - public function coupon() : BelongsTo + /** + * Get the coupon owned by the BasketContent + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function coupon(): BelongsTo { return $this->BelongsTo(Coupon::class); } diff --git a/app/Models/Brand.php b/app/Models/Brand.php index 411fc88..36c1081 100644 --- a/app/Models/Brand.php +++ b/app/Models/Brand.php @@ -2,12 +2,9 @@ namespace App\Models; -use Illuminate\Contracts\Encryption\DecryptException; -use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; -use Illuminate\Support\Facades\Crypt; use App\Lib\Helpers\FileStorageHelper; class Brand extends Model @@ -28,50 +25,27 @@ class Brand extends Model 'crm_password' ]; + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'crm_token' => 'encrypted', + 'crm_password' => 'encrypted', + ]; + + /** + * Get campaign that owned by the Brand + * + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ public function campaigns(): HasMany { return $this->hasMany(Campaign::class); } - /** - * Interact with the brand's crm_token. - */ - protected function crmToken(): Attribute - { - return Attribute::make( - get: function (string $value) { - try { - $decrypted = Crypt::decryptString($value); - } catch (DecryptException $e) { - report($e); - $decrypted = null; - } - return $decrypted; - }, - set: fn (string $value) => Crypt::encryptString($value), - ); - } - - /** - * Interact with the brand's crm_password. - */ - protected function crmPassword(): Attribute - { - return Attribute::make( - get: function (string $value) { - try { - $decrypted = Crypt::decryptString($value); - } catch (DecryptException $e) { - report($e); - $decrypted = null; - } - return $decrypted; - }, - set: fn (string $value) => Crypt::encryptString($value), - ); - } - // * EVENTS /** diff --git a/app/Models/Campaign.php b/app/Models/Campaign.php index 3b95d2c..c3197ac 100644 --- a/app/Models/Campaign.php +++ b/app/Models/Campaign.php @@ -21,11 +21,24 @@ class Campaign extends Model 'type' => CampaignTypes::class, ]; - public function brand() : BelongsTo { + // * RELATIONS + + /** + * Get the brand that owns the Campaign + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function brand(): BelongsTo + { return $this->belongsTo(Brand::class); } - public function coupons() : BelongsToMany + /** + * Get coupons that owned by the Campaign + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function coupons(): BelongsToMany { return $this->belongsToMany(Coupon::class); } diff --git a/app/Models/Coupon.php b/app/Models/Coupon.php index 7daaa0e..23d8d39 100644 --- a/app/Models/Coupon.php +++ b/app/Models/Coupon.php @@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Coupon extends Model { // FIXME : Ajouter les mouvement de quantité, mettre juste une colonne et se servir des logs avec un type pour mouvement ? - // FIXME / Ajouter logs impressions + // FIXME : Ajouter logs impressions. use HasFactory; /** @@ -24,36 +24,54 @@ class Coupon extends Model 'end_validity_date' => 'date:Y-m-d', ]; - public function campaigns() : BelongsToMany + /** + * Get campaigns that owns the Coupon + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function campaigns(): BelongsToMany { return $this->belongsToMany(Campaign::class); } /** * The "booted" method of the model. + * + * @return void */ protected static function booted(): void { static::creating(function (Coupon $coupon) { - $coupon->can_be_used = $this->checkIfCanBeUsed(); + $coupon->can_be_used = self::checkIfCanBeUsed($coupon); }); static::updating(function (Coupon $coupon) { - $coupon->can_be_used = $this->checkIfCanBeUsed(); + $coupon->can_be_used = self::checkIfCanBeUsed($coupon); }); } - public function checkIfCanBeUsed() + /** + * Check if coupon can be used taking account multiple factors + * + * @param \App\Models\Coupon $coupon + * @return boolean + */ + public static function checkIfCanBeUsed(Coupon $coupon): bool { if ( - (is_null($this->start_diffusion_date) or $this->start_diffusion_date->lessThanOrEqualTo(Carbon::now())) and - (is_null($this->end_diffusion_date) or $this->end_diffusion_date->greaterThanOrEqualTo(Carbon::now())) and - (is_null($this->end_validity_date) or $this->end_validity_date->greaterThanOrEqualTo(Carbon::now()->addDays($this->validity_period))) - ){ + ( + is_null($coupon->start_diffusion_date) or + $coupon->start_diffusion_date->lessThanOrEqualTo(Carbon::now()) + ) and + ( + is_null($coupon->end_diffusion_date) or + $coupon->end_diffusion_date->greaterThanOrEqualTo(Carbon::now())) and + (is_null($coupon->end_validity_date) or + $coupon->end_validity_date->greaterThanOrEqualTo(Carbon::now()->addDays($coupon->validity_period)) + ) + ) { return true; } - - // FIXME : Ajouter calendrier de diffusion et le prendre en compte dans la condition - + // FIXME : Ajouter calendrier de diffusion et le prendre en compte dans la condition. return false; } } diff --git a/app/Models/CouponLog.php b/app/Models/CouponLog.php index 6b9d634..7184b30 100644 --- a/app/Models/CouponLog.php +++ b/app/Models/CouponLog.php @@ -9,6 +9,11 @@ class CouponLog extends Model { use HasFactory; + /** + * Fillable + * + * @var string[] + */ protected $fillable = [ 'coupon_id', 'campaign_id', diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 25a86fa..ff1db46 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -9,6 +9,11 @@ class Customer extends Model { use HasFactory; + /** + * Fillable + * + * @var string[] + */ protected $fillable = [ 'hashcode', 'email' From 181621dcf58781663c9de7122449fed8df7a3f4b Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 24 Nov 2023 15:49:44 +0100 Subject: [PATCH 6/8] Add basket model docblock --- app/Models/Basket.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/Models/Basket.php b/app/Models/Basket.php index 86b7c7a..532e376 100644 --- a/app/Models/Basket.php +++ b/app/Models/Basket.php @@ -4,9 +4,23 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Str; +/** + * Basket + * + * @property integer $id Basket Id. + * @property string $reference Basket Reference. + * @property integer $customer_id Basket Cutomer Id. + * @property-read \Carbon\Carbon $created_at Created date. + * @property-read \Carbon\Carbon $updated_at Updated date. + * + * * RELATIONS + * @property-read \App\Models\Customer $customer The content owned by the Basket + * @property-read \App\Models\BasketsContent $content The customer that owns the Basket + */ class Basket extends Model { use HasFactory; @@ -32,6 +46,16 @@ class Basket extends Model return $this->hasMany(BasketsContent::class); } + /** + * Get the customer that owns the Basket + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function customer(): BelongsTo + { + return $this->belongsTo(Customer::class); + } + /** * The "booted" method of the model. * From cae0369710b635018e00bcea67c3ecaeec0ecfb4 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 24 Nov 2023 16:03:46 +0100 Subject: [PATCH 7/8] Some fixes --- app/Providers/AppServiceProvider.php | 6 +++--- .../migrations/2023_08_20_090058_create_coupons_table.php | 4 ++++ .../migrations/2023_08_20_092327_create_brands_table.php | 8 ++++++-- .../2023_08_20_093908_create_campaign_coupon_table.php | 4 ++++ .../2023_08_31_180939_create_customers_table.php | 6 +++++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 5f983d6..3147311 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -35,7 +35,7 @@ class AppServiceProvider extends ServiceProvider return request()->getClientIp(); } else { return request()->server('HTTP_X_FORWARDED_FOR') ?? - request()->getClientIp(); + request()->getClientIp(); } }); @@ -61,9 +61,9 @@ class AppServiceProvider extends ServiceProvider // * FORCE BOOTSTRAP PAGINATOR (or custom if in front) // Early boot, request wont be filled as expected. if (collect(explode('/', \request()->getPathInfo()))->get(1) === 'bo') { - Paginator::useBootstrap(); + Paginator::useBootstrapFive(); } else { - Paginator::useBootstrap(); + Paginator::useBootstrapFive(); } } } diff --git a/database/migrations/2023_08_20_090058_create_coupons_table.php b/database/migrations/2023_08_20_090058_create_coupons_table.php index 441ae0c..b7210e0 100644 --- a/database/migrations/2023_08_20_090058_create_coupons_table.php +++ b/database/migrations/2023_08_20_090058_create_coupons_table.php @@ -8,6 +8,8 @@ return new class extends Migration { /** * Run the migrations. + * + * @return void */ public function up(): void { @@ -37,6 +39,8 @@ return new class extends Migration /** * Reverse the migrations. + * + * @return void */ public function down(): void { diff --git a/database/migrations/2023_08_20_092327_create_brands_table.php b/database/migrations/2023_08_20_092327_create_brands_table.php index 5694151..f9d4cdc 100644 --- a/database/migrations/2023_08_20_092327_create_brands_table.php +++ b/database/migrations/2023_08_20_092327_create_brands_table.php @@ -8,6 +8,8 @@ return new class extends Migration { /** * Run the migrations. + * + * @return void */ public function up(): void { @@ -17,14 +19,16 @@ return new class extends Migration $table->string('contact_mail')->comment("Adresse email de contact"); $table->string('rcs')->comment("RCS"); $table->string('logo')->comment("Path vers le logo - 135x70px JPG"); - $table->string('crm_token', 500)->comment("CRM Token encrypté"); - $table->string('crm_password', 500)->comment("CRM Password encrypté"); + $table->string('crm_token', 280)->comment("CRM Token encrypté"); + $table->string('crm_password', 280)->comment("CRM Password encrypté"); $table->timestamps(); }); } /** * Reverse the migrations. + * + * @return void */ public function down(): void { diff --git a/database/migrations/2023_08_20_093908_create_campaign_coupon_table.php b/database/migrations/2023_08_20_093908_create_campaign_coupon_table.php index a8bd11a..e9cc866 100644 --- a/database/migrations/2023_08_20_093908_create_campaign_coupon_table.php +++ b/database/migrations/2023_08_20_093908_create_campaign_coupon_table.php @@ -8,6 +8,8 @@ return new class extends Migration { /** * Run the migrations. + * + * @return void */ public function up(): void { @@ -19,6 +21,8 @@ return new class extends Migration /** * Reverse the migrations. + * + * @return void */ public function down(): void { diff --git a/database/migrations/2023_08_31_180939_create_customers_table.php b/database/migrations/2023_08_31_180939_create_customers_table.php index 039e247..5950aca 100644 --- a/database/migrations/2023_08_31_180939_create_customers_table.php +++ b/database/migrations/2023_08_31_180939_create_customers_table.php @@ -8,13 +8,15 @@ return new class extends Migration { /** * Run the migrations. + * + * @return void */ public function up(): void { Schema::create('customers', function (Blueprint $table) { $table->id(); $table->string('hashcode', 36); - $table->string('email', 255); + $table->string('email'); $table->timestamps(); $table->unique(['hashcode', 'email']); }); @@ -22,6 +24,8 @@ return new class extends Migration /** * Reverse the migrations. + * + * @return void */ public function down(): void { From 375aae50bfd1a44d87dead25da745bb27355e962 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Fri, 24 Nov 2023 16:05:16 +0100 Subject: [PATCH 8/8] Update faker usage --- database/factories/BrandFactory.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/database/factories/BrandFactory.php b/database/factories/BrandFactory.php index 8acbea9..c0d5290 100644 --- a/database/factories/BrandFactory.php +++ b/database/factories/BrandFactory.php @@ -25,15 +25,15 @@ class BrandFactory extends Factory public function definition() { return [ - 'name' => $this->faker->unique()->company(), - 'contact_mail' => $this->faker->unique()->email(), + 'name' => fake()->unique()->company(), + 'contact_mail' => fake()->unique()->email(), 'rcs' => \sprintf( 'RCS %s B %s', - $this->faker->unique()->city(), - $this->faker->randomNumber(9, true) + fake()->unique()->city(), + fake()->randomNumber(9, true) ), - 'crm_token' => $this->faker->uuid(), - 'crm_password' => $this->faker->uuid() + 'crm_token' => fake()->uuid(), + 'crm_password' => fake()->uuid() ]; } }