0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

419エラーが解決できない時。

Posted at

時間のテストを行おうと、手っ取り早くコンストラクタにテスト時間を設定すると419になります。

Controller.php
public function __construct(){
    parent::__construct();
    Carbon::setTestNow(Carbon::parse('2025-10-01'));
}

こんな感じのを作って、オブジェクト毎に指定すればOK。

TestModeSession.php
<?php

namespace App\Http\Traits;

use Illuminate\Support\Carbon;

trait TestMode {

        /**
     * Display a listing of the resource.
     *
     * @param $parameters
     * @param $type
     * @return bool|LengthAwarePaginator|Builder|Builder[]|Collection|int|mixed[]
     */
    protected function DateTimeTestMode($testdatetime)
    {
        Carbon::setTestNow(Carbon::parse($$testdatetime));
    }

}

時間のテストをしたい時に、コンストラクタにテスト時間を設定すると419が発生するので、コンストラクタにはテスト時間を入れないようにしましょう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?