diff --git a/app/Http/Requests/Api/V2/GetBrandStatsRequest.php b/app/Http/Requests/Api/V2/GetBrandStatsRequest.php index 721ece0..75cc4f9 100644 --- a/app/Http/Requests/Api/V2/GetBrandStatsRequest.php +++ b/app/Http/Requests/Api/V2/GetBrandStatsRequest.php @@ -18,7 +18,7 @@ class GetBrandStatsRequest extends BaseApiRequest public function rules(): array { try { - if (Carbon::parse($this->end)->diffInMonths(Carbon::parse($this->start)->addDay()) >= 3) { + if (Carbon::parse($this->end)->diffInMonths(Carbon::parse($this->start)) >= 3) { throw ValidationException::withMessages([ 'Vous devez sélectionner une période de maximum 3 mois' ]); diff --git a/app/Http/Requests/Api/V2/GetQuestionStatsRequest.php b/app/Http/Requests/Api/V2/GetQuestionStatsRequest.php index ba56b4f..9f759a1 100644 --- a/app/Http/Requests/Api/V2/GetQuestionStatsRequest.php +++ b/app/Http/Requests/Api/V2/GetQuestionStatsRequest.php @@ -19,7 +19,7 @@ class GetQuestionStatsRequest extends BaseApiRequest public function rules(): array { try { - if (Carbon::parse($this->end)->diffInMonths(Carbon::parse($this->start)->addDay()) >= 3) { + if (Carbon::parse($this->end)->diffInMonths(Carbon::parse($this->start)) >= 3) { throw ValidationException::withMessages([ 'Vous devez sélectionner une période de maximum 3 mois' ]); diff --git a/app/Models/Question.php b/app/Models/Question.php index 45797ea..855a86e 100644 --- a/app/Models/Question.php +++ b/app/Models/Question.php @@ -39,7 +39,8 @@ class Question extends Model */ protected $fillable = [ 'question', - 'type' + 'type', + 'brand_id' ]; /** @@ -77,6 +78,7 @@ class Question extends Model 'brand_id' => [ 'label' => Str::ucfirst(trans('models.classes.brand')), 'type' => CrudType::belongsTo(), + 'readonly' => true, 'belongsTo' => Brand::class, 'actions' => [ CrudAction::viewAny(), @@ -94,7 +96,6 @@ class Question extends Model 'actions' => [ CrudAction::viewAny(), CrudAction::view(), - CrudAction::create(), CrudAction::update(), ] ] diff --git a/composer.json b/composer.json index 3ae8e73..4ab8e0a 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "fideloper/proxy": "^4.4", "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^7.0.1", - "kwaadpepper/crud-policies": "^0.3.5", + "kwaadpepper/crud-policies": "^5.0", "kwaadpepper/enum": "^2.1", "kwaadpepper/exception-handler": "^0.0.6", "laravel-lang/lang": "~7.0", diff --git a/composer.lock b/composer.lock index d91ae8f..39d21f3 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": "754ae14d2b3a505a0f58f377d93fc1b9", + "content-hash": "26e67a9e2292d81339b64ea6fd14f70e", "packages": [ { "name": "arondeparon/laravel-request-sanitizer", @@ -1710,16 +1710,16 @@ }, { "name": "kwaadpepper/crud-policies", - "version": "0.3.6", + "version": "5.0.2", "source": { "type": "git", "url": "https://github.com/Kwaadpepper/crud-policies.git", - "reference": "205b8a16c99c362fc78422eeb31c0ba618a3d351" + "reference": "ba3fef154bc5ce7ffe199fa7f2b692a5a410de52" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Kwaadpepper/crud-policies/zipball/205b8a16c99c362fc78422eeb31c0ba618a3d351", - "reference": "205b8a16c99c362fc78422eeb31c0ba618a3d351", + "url": "https://api.github.com/repos/Kwaadpepper/crud-policies/zipball/ba3fef154bc5ce7ffe199fa7f2b692a5a410de52", + "reference": "ba3fef154bc5ce7ffe199fa7f2b692a5a410de52", "shasum": "" }, "require": { @@ -1770,9 +1770,9 @@ ], "support": { "issues": "https://github.com/Kwaadpepper/crud-policies/issues", - "source": "https://github.com/Kwaadpepper/crud-policies/tree/0.3.6" + "source": "https://github.com/Kwaadpepper/crud-policies/tree/5.0.2" }, - "time": "2022-05-04T13:19:25+00:00" + "time": "2022-11-03T16:04:03+00:00" }, { "name": "kwaadpepper/enum", @@ -9179,5 +9179,5 @@ "platform-overrides": { "php": "7.3.26" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/database/migrations/2022_12_01_173016_cascade_delete_question_answers.php b/database/migrations/2022_12_01_173016_cascade_delete_question_answers.php new file mode 100644 index 0000000..37e5431 --- /dev/null +++ b/database/migrations/2022_12_01_173016_cascade_delete_question_answers.php @@ -0,0 +1,36 @@ +dropForeign(['question_id']); + $table->foreign('question_id')->references('id')->on('questions')->cascadeOnDelete(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // * Undo cascade delete (restrict as default) + Schema::table('answers', function (Blueprint $table) { + $table->dropForeign(['question_id']); + $table->foreign('question_id')->references('id')->on('questions'); + }); + } +}