質問編集履歴

1

途中の処理追記

2022/04/18 08:27

投稿

shoco
shoco

スコア170

test CHANGED
File without changes
test CHANGED
@@ -6,3 +6,66 @@
6
6
 
7
7
  よろしくお願いします。
8
8
 
9
+
10
+
11
+ ### 補足
12
+
13
+ ```ここに言語を入力
14
+ <?php
15
+
16
+ namespace App\Http\Requests\Receipt;
17
+
18
+ use Illuminate\Foundation\Http\FormRequest;
19
+ use Illuminate\Contracts\Validation\Validator;
20
+ use Illuminate\Validation\ValidationException;
21
+ use Log;
22
+ use App\Rules\CheckUnworkedReceipt;
23
+ use App\Rules\ItemCodeExists;
24
+ use App\Rules\ReservationStockItemNotExists;
25
+ use App\Rules\ReceiptIsNotDone;
26
+ use App\Rules\ReceiptQuantityIsNotExceed;
27
+ use App\Services\GetNeedForExpirationDateByReceiptedItem;
28
+ use App\Services\Shopify\GraphQL\Query\FetchShopService;
29
+ use App\Services\GetDateFormatService;
30
+ use App\Services\DB\ReceiptedItem\SelectReceiptedItemByItemBarcode;
31
+ use App\Services\CreateCarbonByFormatSettingAndDatestring;
32
+
33
+ class ReceiptDeleteRequest extends FormRequest
34
+ {
35
+ private $const;
36
+ protected $errorBag;
37
+
38
+ public function __construct()
39
+ {
40
+ parent::__construct();
41
+ $this->const = config('const');
42
+ $this->errorBag = get_class($this); //ここの設定の仕方が間違っている?????
43
+ }
44
+
45
+ public function authorize()
46
+ {
47
+ return true;
48
+ }
49
+
50
+ public function rules()
51
+ {
52
+
53
+ $rules = [
54
+ 'receiptNo' => [new CheckUnworkedReceipt($this->receiptNo)] //falseになる(バリデーションひっかかる)
55
+ ];
56
+
57
+ return $rules;
58
+ }
59
+
60
+
61
+ protected function failedValidation(Validator $validator)
62
+ {
63
+ Log::channel($this->processType)->info("$this->processName バリデーションエラー", $validator->errors()->all());
64
+
65
+ throw (new ValidationException($validator))
66
+ ->errorBag($this->errorBag)
67
+ ->redirectTo($this->getRedirectUrl());
68
+ }
69
+ }
70
+
71
+ ```