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?

Laravel11のファイルがコンパクトになっており、いろいろ追加でファイル作成が必要だった

api.phpを追加

Laravel Sanctumをインストール
これだけでもOKみたい php artisan install:api

手動の場合は↓
1 routes/api.phpを作成
2 bootstrap/app.phpにapi: __DIR__.'/../routes/api.php'を追加
3 RouteProviderを作成して、bootstrap/provider.phpに追加

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
    /**
     * This namespace is applied to your controller routes.
     *
     * In addition, it is set as the URL generator's root namespace.
     *
     * @var string
     */
    protected $namespace = 'App\Http\Controllers';

    /**
     * Define your route model bindings, pattern filters, etc.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
    }

    /**
     * Define the routes for the application.
     *
     * @return void
     */
    public function map()
    {
        $this->mapApiRoutes();
        $this->mapWebRoutes();
    }

    /**
     * Define the "web" routes for the application.
     *
     * These routes all receive session state, CSRF protection, etc.
     *
     * @return void
     */
    protected function mapWebRoutes()
    {
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(base_path('routes/web.php'));
    }

    /**
     * Define the "api" routes for the application.
     *
     * These routes are typically stateless.
     *
     * @return void
     */
    protected function mapApiRoutes()
    {
        Route::prefix('api')
             ->middleware('api')
             ->namespace($this->namespace)
             ->group(base_path('routes/api.php'));
    }
}

cors通信可能に

デフォルトで通信はできるがセキュリティ的にガバガバなので調整が必要

php artisan config:publish cors

API通信ができなくて苦戦

5時間くらい時間がかかってしまった
原因はengixのdefault.conf設定が原因だった

Sanctumで認証

下を完全参考
https://qiita.com/genkaitoppa_programmer/items/dbf54c2cf9822a66bddd

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?