12
8

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 3 years have passed since last update.

LaravelでControllerをサブディレクトリに作成する方法

Last updated at Posted at 2019-08-05

##やりたいこと

Controllers
├Example-ExampleController.php
このようにサブディレクトリにControllerを作成します。
Exampleディレクトリは無くても自動生成されます。

##環境
php -7.3.8
laravel -5.8.30

##コマンド

コマンドライン
//例文
php artisan make:controller Example/ExampleController

##コード
web.phpにルーティングの設定を記述します。

web.php
Route::resource('/examples', 'Example\ExampleController');

あるいは名前空間を指定することもできます。

web.php
Route::namespace('Example')->group(function() {
    Route::resource('/examples', 'ExampleController');
}
12
8
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
12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?