Readouble

Laravel master ディレクトリ構造

イントロダクションIntroduction

Laravelのデフォルトアプリケーション構造はアプリケーションの大小にかかわらず、素晴らしいスタートを切ってもらえることを意図しています。もちろんアプリケーションは皆さんのお好みに応じ、自由に体系立ててください。クラスがComposerによりオートローディングできるならば、Laravelはクラスをどこに配置するか強制することはまずありません。The default Laravel application structure is intended to provide a great starting point for both large and small applications. Of course, you are free to organize your application however you like. Laravel imposes almost no restrictions on where any given class is located - as long as Composer can autoload the class.

modelsディレクトリはどこにある?Where Is The Models Directory?

Laravelを学習し始めるとき、多くの開発者はmodelsディレクトリが存在しないことに戸惑います。しかし、意図的にこのディレクトリを用意していません。多くの別々の人達にとって、その意味合いは様々なため、"models"という言葉の定義は曖昧であることに私達は気づきました。ある開発者たちはすべてのビジネスロジックを総称してアプリケーションの「モデル」と呼び、一方で別の人達はリレーショナルデータベースに関連するクラスを「モデル」として参照しています。When getting started with Laravel, many developers are confused by the lack of a models directory. However, the lack of such a directory is intentional. We find the word "models" ambiguous since it means many different things to many different people. Some developers refer to an application's "model" as the totality of all of its business logic, while others refer to "models" as classes that interact with a relational database.

このため、私達はEloquentモデルをデフォルトではappディレクトリ下へ設置することを選択し、開発者自分が選んだどこか別の場所へ設置してもらうことにしました。For this reason, we choose to place Eloquent models in the app directory by default, and allow the developer to place them somewhere else if they choose.

プロジェクトディレクトリThe Root Directory

appディレクトリThe App Directory

appディレクトリは名前の示すとおり、アプリケーションのコアコードを配置します。このフォルダーの詳細は、このあとに説明します。しかし、アプリケーションのほとんど全部のクラスは、このディレクトリの中に設定されることを覚えておいてください。The app directory, as you might expect, contains the core code of your application. We'll explore this directory in more detail soon; however, almost all of the classes in your application will be in this directory.

bootstrapディレクトリThe Bootstrap Directory

bootstrapフォルダーはフレームワークの初期起動やオートローディングの設定を行うファイルを含んでいます。その中のcacheディレクトリは、初期処理のパフォーマンスを最適化するため、フレームワークが生成するルートやサービスのキャッシュファイルが保存されるフォルダーです。The bootstrap directory contains files that bootstrap the framework and configure autoloading. This directory also houses a cache directory which contains framework generated files for performance optimization such as the route and services cache files.

ConfigディレクトリThe Config Directory

configディレクトリは名前が示す通り、アプリケーションの全設定ファイルが設置されています。全ファイルに目を通し、設定可能なオプションに慣れ親しんでおくのは良い考えでしょう。The config directory, as the name implies, contains all of your application's configuration files. It's a great idea to read through all of these files and familiarize yourself with all of the options available to you.

databaseディレクトリThe Database Directory

databaseフォルダーはデータベースのマイグレーションと初期値設定(シーディング)を配置します。ご希望であれば、このファイルをSQLiteデータベースの設置場所としても利用できます。The database directory contains your database migration and seeds. If you wish, you may also use this directory to hold an SQLite database.

publicディレクトリThe Public Directory

publicディレクトリは、アプリケーションへの全リクエストの入り口となるindex.phpファイルを持っています。また、このディレクトリにはアセット(画像、JavaScript、CSSなど)を配置します。The public directory contains the index.php file, which is the entry point for all requests entering your application. This directory also houses your assets such as images, JavaScript, and CSS.

resourcesディレクトリThe Resources Directory

resourcesディレクトリはビューやアセットの元ファイル(LESS、SASS、JavaScript)で構成されています。また、すべての言語ファイルも配置します。The resources directory contains your views as well as your raw, un-compiled assets such as LESS, SASS, or JavaScript. This directory also houses all of your language files.

routesディレクトリThe Routes Directory

routesディレクトリはアプリケーションの全ルート定義により構成されています。デフォルトでは、web.phpapi.phpconsole.phpの3ファイルが含まれています。The routes directory contains all of the route definitions for your application. By default, three route files are included with Laravel: web.php, api.php, and console.php.

Web.phpファイルは、RouteServiceProviderwebミドルウェアグループに属するルートで構成します。このミドルウェアは、セッションステート、CSRF保護、クッキーの暗号化機能を提供しています。もしアプリケーションがステートレスではなく、RESTフルなAPIを提供しないのであれば、すべてのルートはweb.phpファイルの中で定義されることになるでしょう。The web.php file contains routes that the RouteServiceProvider places in the web middleware group, which provides session state, CSRF protection, and cookie encryption. If your application does not offer a stateless, RESTful API, all of your routes will most likely be defined in the web.php file.

api.phpファイルは、RouteServiceProviderapiミドルウェアグループに属するルートで構成します。このミドルウェアはアクセス回数制限を提供しています。このファイル中で定義されるルートは、ステートレスであることを意図しています。つまり、これらのルートを通るアプリケーションに対するリクエストは、セッションステートにアクセスする必要がないように、トークンを使って認証されることを意図しています。The api.php file contains routes that the RouteServiceProvider places in the api middleware group, which provides rate limiting. These routes are intended to be stateless, so requests entering the application through these routes are intended to be authenticated via tokens and will not have access to session state.

console.phpファイルは、クロージャベースの全コンソールコマンドを定義する場所です。それぞれのコマンドのIOメソッドと連携するシンプルなアプローチを提供するコマンドインスタンスと、各クロージャは結合します。厳密に言えば、このファイルはHTTPルートは定義していないのですが、コンソールベースのエントリポイントを定義しているという点で、ルート定義なのです。The console.php file is where you may define all of your Closure based console commands. Each Closure is bound to a command instance allowing a simple approach to interacting with each command's IO methods. Even though this file does not define HTTP routes, it defines console based entry points (routes) into your application.

storageディレクトリThe Storage Directory

storageディレクトリにはコンパイルされたBladeテンプレート、ファイルベースのセッション、ファイルキャッシュなど、フレームワークにより生成されるファイルが保存されます。このフォルダーはappframeworklogsディレクトリに分かれています。appディレクトリはアプリケーションにより生成されるファイルを保存するために利用します。frameworkディレクトリはフレームワークが生成するファイルやキャッシュに利用されます。最後のlogsディレクトリはアプリケーションのログファイルが保存されます。The storage directory contains your compiled Blade templates, file based sessions, file caches, and other files generated by the framework. This directory is segregated into app, framework, and logs directories. The app directory may be used to store any files generated by your application. The framework directory is used to store framework generated files and caches. Finally, the logs directory contains your application's log files.

storage/app/publicディレクトリにはプロファイルのアバターなどのようなユーザにより生成され、外部からアクセスされるファイルが保存されます。public/storageがこのディレクトリを指すように、シンボリックリンクを張る必要があります。リンクは、php artisan storage:linkコマンドを使い生成できます。The storage/app/public directory may be used to store user-generated files, such as profile avatars, that should be publicly accessible. You should create a symbolic link at public/storage which points to this directory. You may create the link using the php artisan storage:link command.

testsディレクトリThe Tests Directory

testsディレクトリには皆さんの自動テストを配置します。サンプルのPHPUnitテストが最初に含まれています。各テストクラスはサフィックスとしてTestを付ける必要があります。テストはphpunitか、php vendor/bin/phpunitコマンドにより実行できます。The tests directory contains your automated tests. An example PHPUnit[https://phpunit.de/] is provided out of the box. Each test class should be suffixed with the word Test. You may run your tests using the phpunit or php vendor/bin/phpunit commands.

vendorディレクトリThe Vendor Directory

vendorディレクトリには、Composerによる依存パッケージが配置されます。The vendor directory contains your Composer[https://getcomposer.org] dependencies.

appディレクトリThe App Directory

皆さんのアプリケーションの主要な部分は、appディレクトリー内に配置します。このディレクトリーはデフォルトで、App名前空間のもとに置かれており、PSR-4オートローディング規約を使い、Composerがオートロードしています。The majority of your application is housed in the app directory. By default, this directory is namespaced under App and is autoloaded by Composer using the PSR-4 autoloading standard[http://www.php-fig.org/psr/psr-4/].

appディレクトリは多様なサブディレクトリを持っています。ConsoleHttpProvidersなどです。ConsoleHttpディレクトリは、アプリケーションの「コア」へAPIを提供していると考えてください。HTTPプロトコルとCLIは両方共にアプリケーションと相互に関係するメカニズムですが、実際のアプリケーションロジックではありません。言い換えれば、これらはアプリケーションに指示を出す、2つの方法に過ぎません。Consoleディレクトリは全Artisanコマンドで構成され、一方のHttpディレクトリはコントローラーやフィルター、リクエストにより構成されています。The app directory contains a variety of additional directories such as Console, Http, and Providers. Think of the Console and Http directories as providing an API into the core of your application. The HTTP protocol and CLI are both mechanisms to interact with your application, but do not actually contain application logic. In other words, they are simply two ways of issuing commands to your application. The Console directory contains all of your Artisan commands, while the Http directory contains your controllers, middleware, and requests.

クラスを生成するためのmake Artisanコマンドを使用することにより、その他様々なディレクトリがappディレクトリ内に作成されます。たとえばapp/Jpbsディレクトリは、ジョブクラスを生成するmake:job Artisanコマンドを実行するまで存在していません。A variety of other directories will be generated inside the app directory as you use the make Artisan commands to generate classes. So, for example, the app/Jobs directory will not exist until you execute the make:job Artisan command to generate a job class.

lightbulb">Tip!! Artisanコマンドにより、appディレクトリ下にたくさんのクラスが生成されます。使用可能なコマンドを確認するには、php artisan list makeコマンドをターミナルで実行してください。{tip} Many of the classes in the app directory can be generated by Artisan via commands. To review the available commands, run the php artisan list make command in your terminal.

ConsoleディレクトリThe Console Directory

Consoleディレクトリは、アプリケーションの全カスタムArtisanコマンドで構成します。これらのコマンドクラスはmake:commandコマンドにより生成されます。コンソールカーネルもこのディレクトリ内にあり、カスタムArtisanコマンドや、タスクのスケジュールを登録します。The Console directory contains all of the custom Artisan commands for your application. These commands may be generated using the make:command command. This directory also houses your console kernel, which is where your custom Artisan commands are registered and your scheduled tasks[/docs/{{version}}/scheduling] are defined.

EventsディレクトリThe Events Directory

このディレクトリはデフォルトで存在していません。event:generatemake:event Artisanコマンド実行時に作成されます。Eventsディレクトリは名前の通り、イベントクラスを設置する場所です。イベントは特定のアクションが起きたことをアプリケーションの別の部分に知らせるために使われ、柔軟性と分離性を提供しています。This directory does not exist by default, but will be created for you by the event:generate and make:event Artisan commands. The Events directory, as you might expect, houses event classes[/docs/{{version}}/events]. Events may be used to alert other parts of your application that a given action has occurred, providing a great deal of flexibility and decoupling.

ExceptionsディレクトリThe Exceptions Directory

Exceptionsディレクトリはアプリケーションの例外ハンドラで構成します。また、アプリケーションから投げる例外を用意するにも適した場所でしょう。例外のログやレンダー方法をカスタマイズしたい場合は、このディレクトリのHandlerクラスを修正してください。The Exceptions directory contains your application's exception handler and is also a good place to place any exceptions thrown by your application. If you would like to customize how your exceptions are logged or rendered, you should modify the Handler class in this directory.

HttpディレクトリThe Http Directory

Httpディレクトリはコントローラ、ミドルウェア、フォームリクエストを設置します。アプリケーションへのリクエストを処理するロジックは、ほぼ全てこのディレクトリ内に設置します。The Http directory contains your controllers, middleware, and form requests. Almost all of the logic to handle requests entering your application will be placed in this directory.

JobsディレクトリThe Jobs Directory

このディレクトリはデフォルトで存在していません。make:job Artisanコマンドを実行すると作成されます。Jobsディレクトリーはアプリケーションのキュー投入可能なジョブを置いておく場所です。Jobsはアプリケーションによりキューに投入されるか、もしくは現在のリクエストサイクル中に同期的に実行されます。現在のリクエストサイクル中に同期的に実行するジョブは、コマンドパターンを実装しているため、時に「コマンド」と呼ばれることがあります。This directory does not exist by default, but will be created for you if you execute the make:job Artisan command. The Jobs directory houses the queueable jobs[/docs/{{version}}/queues] for your application. Jobs may be queued by your application or run synchronously within the current request lifecycle. Jobs that run synchronously during the current request are sometimes referred to as "commands" since they are an implementation of the command pattern[https://en.wikipedia.org/wiki/Command_pattern].

ListenersディレクトリThe Listeners Directory

Tこのディレクトリはデフォルトで存在していません。event:generatemake:listener Artisanコマンドを実行すると、作成されます。Listenersディレクトリには、eventsイベントを処理するクラスを設置します。イベントリスナはイベントインスタンスを受け取り、発行されたイベントへ対応するロジックを実行します。たとえば、UserRegistered(ユーザ登録)イベントは、SendWelcomeEmail(ウェルカムメール送信)リスナにより処理されることになるでしょう。This directory does not exist by default, but will be created for you if you execute the event:generate or make:listener Artisan commands. The Listeners directory contains the classes that handle your events[/docs/{{version}}/events]. Event listeners receive an event instance and perform logic in response to the event being fired. For example, a UserRegistered event might be handled by a SendWelcomeEmail listener.

MailディレクトリThe Mail Directory

このディレクトリはデフォルトでは存在していません。make:mall Artisanコマンドを実行すると、作成されます。Mailディレクトリは、アプリケーションから送信されるメールを表す全クラスで構成します。メールオブジェクトにより、Mail::sendメソッドを使用して送られるメールを組み立てるロジックをすべて、1つのシンプルなクラスへカプセル化できます。This directory does not exist by default, but will be created for you if you execute the make:mail Artisan command. The Mail directory contains all of your classes that represent emails sent by your application. Mail objects allow you to encapsulate all of the logic of building an email in a single, simple class that may be sent using the Mail::send method.

NotificationsディレクトリThe Notifications Directory

このディレクトリはデフォルトでは存在していません。make:notification Artisanコマンドを実行すると作成されます。Notificationsディレクトリは、アプリケーションから送られる全「業務上」の通知、たとえばアプリケーションの中でイベントが発生したことを知らせるシンプルな通知などで構成します。Laravelの通知機能は、メール、Slack、SMS、データベースへの保存などのように、様々なドライブに対する通知の送信を抽象化しています。This directory does not exist by default, but will be created for you if you execute the make:notification Artisan command. The Notifications directory contains all of the "transactional" notifications that are sent by your application, such as simple notifications about events that happen within your application. Laravel's notification features abstracts sending notifications over a variety of drivers such as email, Slack, SMS, or stored in a database.

PoliciesディレクトリThe Policies Directory

このディレクトリはデフォルトでは存在していません。make:policy Artisanコマンドを実行すると、作成されます。Policiesディレクトリにはアプリケーションの認可ポリシークラスを設置します。ポリシーは、リソースに対し指定したアクションをユーザが実行できるかを決定します。詳細は、認可のドキュメントをご覧ください。This directory does not exist by default, but will be created for you if you execute the make:policy Artisan command. The Policies directory contains the authorization policy classes for your application. Policies are used to determine if a user can perform a given action against a resource. For more information, check out the authorization documentation[/docs/{{version}}/authorization].

ProvidersディレクトリThe Providers Directory

Providersディレクトリは、アプリケーションの全サービスプロバイダにより構成します。サービスプロバイダは、サービスをコンテナと結合、イベントの登録、もしくはアプリケーションへやってくるリクエストを処理するために必要な用意をするタスクを実行するなど、アプリケーションの事前準備を行います。The Providers directory contains all of the service providers[/docs/{{version}}/providers] for your application. Service providers bootstrap your application by binding services in the service container, registering events, or performing any other tasks to prepare your application for incoming requests.

インストール直後のアプリケーションでも、このディレクトリは多くのプロパイダーを含んでいます。必要に応じて、自分のプロバイダーを自由に追加してください。In a fresh Laravel application, this directory will already contain several providers. You are free to add your own providers to this directory as needed.

章選択

開発環境
ビューとテンプレート
公式パッケージ

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作