1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Laravel api.phpに記載したURLがデフォルトで/apiついてしまう件

Last updated at Posted at 2022-03-10

LaravelでAPI作成のした際にルーティングでroutes/api.phpに記載すると /api/〜になってしまう。

/api部分を無くすためには以下を削除すればいい。

app/Providers/RouteServiceProvider.php
Route::prefix('api') //prefixを削除
         ->middleware('api')
         ->namespace($this->namespace)
         ->group(base_path('routes/api.php'));

これと同じ挙動でweb.phpなどでも活用できる

Route::prefix('user')->group(function () {
    Route::post('/', 'App\Http\Controllers\UserController@index');
    Route::post('create', 'App\Http\Controllers\UserController@create');
});

prefix使えばまとめることも簡単ですね。

1
2
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?