Directory Structure

ほう、英語ではDirectory structureと表現するのか。

Introduction
Where Is The Models Directory?
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.

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.

appディレクトリを見よ。user.phpがmodel, httpのcontrollerがコントローラーか。

The Root Directory
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.
appディレクトリが基礎となる。

The Bootstrap Directory
The bootstrap directory contains the app.php file which bootstraps the framework. This directory also houses a cache directory which contains framework generated files for performance optimization such as the route and services cache files.
あ、ホントだ、app.phpとcacheフォルダがある。

The Config Directory
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.
config file全部見ろ、って言ってるwwww
しょうがない、見るか。全部returnで始まるね。
あ、s3に対応している、すげー
メールも充実しているね。smtpって随分出てくるけど、smtpの機能持ってるってこと??
なんだこりゃ、document読むのが一番手っ取り早い!

The Database Directory
The database directory contains your database migrations, model factories, and seeds. If you wish, you may also use this directory to hold an SQLite database.
migrateすると、ここにファイルができるのかな。

The Public Directory
The public directory contains the index.php file, which is the entry point for all requests entering your application and configures autoloading. This directory also houses your assets such as images, JavaScript, and CSS.
ここは、フロントのファイル群です。

The Resources Directory
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.
view, sass, jsを入れるといってる。viewは解るが、sassはフロントでなくここ? jsでpublicとresourcesの違いは??

The Routes Directory
The routes directory contains all of the route definitions for your application. By default, several route files are included with Laravel: web.php, api.php, console.php and channels.php.
たのフレームワークと被るな。

主に触るのはweb.phpか。

The Storage Directory
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.

The Tests Directory
The tests directory contains your automated tests. An example PHPUnit 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.

The Vendor Directory
The vendor directory contains your Composer dependencies.
眠くなってきた。

Accessing Configuration Values

You may easily access your configuration values using the global config helper function from anywhere in your application. The configuration values may be accessed using “dot” syntax, which includes the name of the file and option you wish to access. A default value may also be specified and will be returned if the configuration option does not exist:

$value = config('app.timezone');

あーなるほど、configの値を持ってこれるのね。面白いなこれ。
To set configuration values at runtime, pass an array to the config helper:

config(['app.timezone' => 'America/Chicago']);

なるほど、なるほど。完全にドキュメントを先に学んだ方がいいね、これは。

Configuration Caching
To give your application a speed boost, you should cache all of your configuration files into a single file using the config:cache Artisan command. This will combine all of the configuration options for your application into a single file which will be loaded quickly by the framework.
config:cacheを使えと言ってます。

Maintenance Mode
When your application is in maintenance mode, a custom view will be displayed for all requests into your application. This makes it easy to “disable” your application while it is updating or when you are performing maintenance. A maintenance mode check is included in the default middleware stack for your application. If the application is in maintenance mode, a MaintenanceModeException will be thrown with a status code of 503.

php artisan down

実務的にはよく使います。これは、503.phpを表示させたい。

You may also provide message and retry options to the down command. The message value may be used to display or log a custom message, while the retry value will be set as the Retry-After HTTP header’s value:

php artisan down --message="Upgrading Database" --retry=60

Even while in maintenance mode, specific IP addresses or networks may be allowed to access the application using the command’s allow option:

php artisan down --allow=127.0.0.1 --allow=192.168.0.0/16

これすげーーーーー、こんなの出来るんだ。
To disable maintenance mode, use the up command:

php artisan up

Maintenance Mode & Queues
While your application is in maintenance mode, no queued jobs will be handled. The jobs will continue to be handled as normal once the application is out of maintenance mode.

Alternatives To Maintenance Mode
Since maintenance mode requires your application to have several seconds of downtime, consider alternatives like Envoyer to accomplish zero-downtime deployment with Laravel.
なるほどばっかだーーーーー

Laravel Configuration

Introduction
All of the configuration files for the Laravel framework are stored in the config directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.

config fileに全て入っているのは先ほど見た通りです。

Environment Configuration
It is often helpful to have different configuration values based on the environment where the application is running. For example, you may wish to use a different cache driver locally than you do on your production server.
ローカルのキャッシュドライバーを使えと言ってます。

To make this a cinch, Laravel utilizes the DotEnv PHP library by Vance Lucas. In a fresh Laravel installation, the root directory of your application will contain a .env.example file. If you install Laravel via Composer, this file will automatically be renamed to .env. Otherwise, you should rename the file manually.
.envファイルは大事です。

app, db, redis, mailなどの記載があります。

Your .env file should not be committed to your application’s source control, since each developer / server using your application could require a different environment configuration. Furthermore, this would be a security risk in the event an intruder gains access to your source control repository, since any sensitive credentials would get exposed.
git hubには.envはpushするなって書いてます。レポジトリを見ましたが、上がっていません。

If you are developing with a team, you may wish to continue including a .env.example file with your application. By putting place-holder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application. You may also create a .env.testing file. This file will override the .env file when running PHPUnit tests or executing Artisan commands with the –env=testing option.
teamなら.env.exampleを使えと言ってます。デフォルトでは.envと内容が一緒です。

Retrieving Environment Configuration
コード入力入っていきます。

'debug' => env('APP_DEBUG', false),

The current application environment is determined via the APP_ENV variable from your .env file. You may access this value via the environment method on the App facade:

Hiding Environment Variables From Debug Pages
debugのblackリストを設定できる?

return [

    // ...

    'debug_blacklist' => [
        '_ENV' => [
            'APP_KEY',
            'DB_PASSWORD',
        ],

        '_SERVER' => [
            'APP_KEY',
            'DB_PASSWORD',
        ],

        '_POST' => [
            'password',
        ],
    ],
];

laravel Nginx

Nginx
If you are using Nginx, the following directive in your site configuration will direct all requests to the index.php front controller:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

Of course, when using Homestead or Valet, pretty URLs will be automatically configured.

む、apacheとnginxだとroutingが違うということか。

まず、apacheのversion確認
[vagrant@localhost ~]$ httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Jun 19 2018 15:45:13

apacheのHP
https://httpd.apache.org/
Apache httpd 2.4.37 Released 2018-10-23
お、大分差がありますね。

apachectlでも確認できる。
[vagrant@localhost ~]$ apachectl -v
Server version: Apache/2.2.15 (Unix)
Server built: Jun 19 2018 15:45:13

バージョン2.2系は、2005年12月1日にリリースされ、後述する2.4系が発表されるまで主流だったバージョンであり、現在でも利用しているユーザーは少なくない

バージョン2.4系は、これまでのApacheと比べて、メモリ使用量を削減するためにシステムを改善したり、あらゆるMPMをモジュールとしてビルド可能にする新機能などを追加したりという変更を施された最新のバージョン

なるほど、2.4系が主流ってことのよう。

[vagrant@localhost ~]$ nginx -V
-bash: nginx: コマンドが見つかりません

nginx が入ってない。入れるか。

laravel Web Server Configuration

Pretty URLs
Apache
Laravel includes a public/.htaccess file that is used to provide URLs without the index.php front controller in the path. Before serving Laravel with Apache, be sure to enable the mod_rewrite module so the .htaccess file will be honored by the server.

.htaccessを見てみましょう

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

あれ、ナニコレ、要するに、laravelのroutingってrewriteEngineで301リダイレクトさせてるってこと!?
Handle Authorization Header、Redirect Trailing Slashes If Not A Folder…、Handle Front Controller…って書いてますね。

RewriteCondはRewriteRule を実行するための条件を定義するための記述
ってことは、 %{HTTP:Authorization}、%{REQUEST_FILENAME}、%{REQUEST_URI} この辺は条件か。
REQUEST_URI リクエストURI
REQUEST_FILENAME リクエストされたファイル名

あーーーーーーなるほど、ドキュメントはやべーわ。フレームワークの重要なこと、全部書かれてるっぽい。
なるほど、フレームワーク使う時は、ドキュメント全部読まないと駄目だわこりゃ。
うわーーーーーーー頭いてー

Laravel Configuration

All of the configuration files for the Laravel framework are stored in the config directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.

configファイルは、app.php, auth.php, broadcasting.php, cache.php … などが入っています。
app.phpは.envやtime zoneなどでしたね。

Directory Permissions
After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run. If you are using the Homestead virtual machine, these permissions should already be set.
ん? storageもresources/viewsもpublicも、いずれも755では。。。

Additional Configuration
Laravel needs almost no other configuration out of the box. You are free to get started developing! However, you may wish to review the config/app.php file and its documentation. It contains several options such as timezone and locale that you may wish to change according to your application.
あ、やっぱりconfig/app.php はまず見ておいた方が良さそうです。

asia/tokyoに変えます。localeも’ja’に。

'timezone' => 'Asia/Tokyo',
'locale' => 'ja',

あれ、リンクっぽいのがあるぞ、試しに踏んでみよう。
https://readouble.com/laravel/5.7/en/cache.html#configuration
https://readouble.com/laravel/5.7/en/database.html#configuration
https://readouble.com/laravel/5.7/en/session.html#configuration

ぎゃあああああああああああああああああああああああああ
がっつりリンクあるやんけ。
みなけりゃ良かった。。

あれ、俺が見てるのって、instalationのドキュメントじゃん。
シンプルなのはinstalltionだけで、ドキュメントすげーいっぱいあるじゃん。これ全部読むの?
まじかーーー、週末までかかるな。。。

Laravel Document

日本語と英語があります。
https://readouble.com/laravel/

当然英語でしょ!常識!
https://readouble.com/laravel/5.7/en/installation.html

requirement
PHP >= 7.1.3
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension
Ctype PHP Extension
JSON PHP Extension

7.1.3か~ vagrantを見てみましょう。
[vagrant@localhost ~]$ php -v
PHP 7.1.21 (cli) (built: Aug 15 2018 18:11:46) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

php info(); を見てみます。
openssl, PDO driver, mbstring, tokenizer, xml, ctype Hartmut Holzgraefe, json 入ってますね。
なるほど、確かにプロとしてサービス提供するならドキュメントはしっかり読んだ方が良さそうだ。

composerの入れ方について説明があります。ここはスキップでも大丈夫ですな。

composer create-project --prefer-dist laravel/laravel blog

Local Development Server
割とシンプルなドキュメントだな、これ。

php artisan serve
[/php]

Configuration
Public Directory
After installing Laravel, you should configure your web server’s document / web root to be the public directory.
お、いきなりMVCに踏み込んできた。
public が publicディレクトリ

laravelのドキュメントを読み解く

jpのTopページに記載の内容
http://laravel.jp/

1.RESTfulルーティング・・・RESTfulなインターフェイスとはRESTの特徴を備えたルートのことを言う。 RESTとはWebに運用したソフトウェア設計様式のこと。 これはURLで表現することができる。つまりURLに対してHTTPのメソッド
GET(取得) ・POST(作成) ・PATCH(PUT)(更新) ・DELETE(削除)を使う
Restとは… 分散型システムにおける複数のソフトウェアを連携させるのに適した設計原則
→ Restの設計原則に沿ったルーティングということね。

2.コマンドYour Date・・・素晴らしい Eloquent ORM と 素晴らしいマイグレーションシステムを完備
Eloquent ORMは、laravelで用意されているデータ操作の為の機能。 データベースとモデルを関連付け、柔軟なデータ操作を行う為のLaravel独自の機能
→ modelのところか。

3. 美しいテンプレート・・・在来の PHP 、もしくは軽量の Blade テンプレート・エンジン。Blade を好きになるでしょう。
→ Laravelで標準搭載されているけども、laravel以外、ex. wordpressでも使えるみたいですな。

4. 明日の準備
→ skip

5. 実績ある土台・・・Laravel は Symfony コンポーネントの上に構築
Symfonyは Model View Controller (MVC) パラダイムに従ったWebアプリケーションフレームワークで、PHPで書かれている
公式 https://symfony.com/
→ symfonyは前に少し触ったことがあります。

6. Composerで動く・・・Composer はあなたの適用のサードパッケージを管理する、驚くべきツール
→ vagrantで入れています。

7. 最高のコミュニティ・・・Laravel の事について日本語で議論できるコミュニティがある
→ doorkeeper って2016年かい!
https://laravel.doorkeeper.jp/

laravelでユーザー管理

管理者、閲覧者など、権限によって、閲覧、編集を制限したり、表示するページを出し分けたい。

ということだが、ドキュメントを全部見ろ、とのこと。
http://laravel.jp/

tinymceの機能を考えてた時も、「ドキュメント全部読め」って怒られたけど、どうやらドキュメント読むのは基本のようね。ということで、laravelのドキュメントを読み進めたいと思います。