0
2

More than 3 years have passed since last update.

Laravelでapi.phpに送れない

Posted at

何をしているか

https://www.hypertextcandy.com/vue-laravel-tutorial-authentication-part-4/
上記サイトを参考にLaravel × Vue のアプリ開発の勉強をしています

ただ、Laravelの更新により、現在のバージョンではコピペでエラーが出てしまうことがありました。

躓いた箇所

上記サイトのところで、api.phpにgetを渡したのにも関わらず、web.phpの
Route::get('/{any?}', fn() => view('index'))->where('any', '.+');
が参照されてしまいました。

解決策

app\Providers\RouteServiceProvider.php の箇所で

public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::middleware('web')
                ->group(base_path('routes/web.php'));

            Route::prefix('api')
                ->middleware('web')
                ->group(base_path('routes/api.php'));
        });
    }

となっている箇所を

public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::prefix('api')
                ->middleware('web')
                ->group(base_path('routes/api.php'));
            Route::middleware('web')
                ->group(base_path('routes/web.php'));
        });
    }

に変更しました。
要するにwebとapi の読み込む順番を逆にするということです。

同じところで躓いた人は試してみてください。

0
2
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
2