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?

Breeze APIわからない

Last updated at Posted at 2025-02-16

Reactの方は全然わからなかったので復習しようと思います。
参考にしたサイト

↓これ大事っぽい

  withXSRFToken: true,
  withCredentials: true,

Laravel

定数の定義

色々方法があるっぽい

  • 'config/const.php'ファイルを作製する
  • constructフォルダを作製する
  • Enumsを作製する
    php8.1からEnumが追加されたそうで調べた感じ結構みんなEnum使ってそう

logのパーミッションエラー

まだ、未確認だがこれでパーミッションのエラーは解決するっぽい

api/config/logging.php
        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/laravel.log'),
            'level' => env('LOG_LEVEL', 'debug'),
            // 'days' => 14,
            'days' => env('LOG_MAX_DAYS', 14),
            'permission' => 0775,←ここを追加したらいいらしい
            'replace_placeholders' => true,
        ],

web.phpを消して復元したらも元に戻らなかった

こんな感じのエラーが出たけど解決できなかった

Target class [web] does not exist.
require(/src/api/routes/web.php): Failed to open stream: No such file or direc

sunctumをapiルーティングにしたいとき

api/config/sanctum.php'routes' => false,を追加

何が何かあんまり理解できなかったので見返し用に

sessionやcookie周りのエラー
ここを何を設定しているか確認
api/config/session.php

    'driver' => env('SESSION_DRIVER', 'file'),
    'domain' => env('SESSION_DOMAIN'),
    'secure' => env('SESSION_SECURE_COOKIE'),

api/app/Http/Kernel.php

    protected $middlewareGroups = [
        'api' => [
            /************sessionが使えるように追加************/
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            /************sessionが使えるように追加************/
        ],
    ];

api/vendor/laravel/sanctum/src/Http/Middleware/EnsureFrontendRequestsAreStateful.php

fromFrontendメソッドでlog出してみた

stateful: [(configのsanctum.statefulに書いてあるもの)]  
domain: フロントのドメインに/を付けてた  
is: 1  ←return

419のエラーについて

ちょっと上の方にも載せてるけど補足。
api/app/Http/Kernel.phpこのファイルのmiddlewareGroupsのapiの中に下記が要らない

\App\Http\Middleware\VerifyCsrfToken::class,

Cookieが書き込まれない

.envのこの設定がよくないです。
フロント側とcookieの名前を合わせなくてはなりません。

SESSION_DOMAIN=

401エラーについて

バックエンド側が悪かった。
api/app/Http/Controllers/Auth/AuthenticatedSessionController.php
このファイルでtoken送ってるか確認して、送ってあげればエラーが解消する
このファイルを何もいじっていなければ特に問題ないと思います。

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?