そろそろLaravelも学ばないと。そんなわけで今日から地道に。
こちら環境はWindows10pro
1.Composerのインストール
composer(コンポーザ)はPHPのパッケージ管理プログラム。早速まずはXAMPPを入れてから指定。
まずはダウンロード
https://getcomposer.org/
setup.exeからダウンロード
PHPの場所を指定。
Laravelのインストール
DOSコマンドプロンプトで指定の場所に移動。私はDドライブにいれたので、移動してテストディレクトリを用意。
d:\xampp\htdocs>cd d:\xampp\htdocs
mkdir test_laravel
インストール開始
composer global require "laravel/installer=~1.1"
結構かかる、23:22~23:24 2分程掛かった。
d:\xampp\htdocs>composer global require "laravel/installer=~1.1" Changed current directory to C:/Users/kato.SG/AppData/Roaming/Composer ./composer.json has been created Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 9 installs, 0 updates, 0 removals - Installing symfony/process (v4.0.3): Downloading (100%) - Installing symfony/filesystem (v4.0.3): Downloading (100%) - Installing symfony/polyfill-mbstring (v1.6.0): Downloading (100%) - Installing symfony/console (v4.0.3): Downloading (100%) - Installing guzzlehttp/promises (v1.3.1): Downloading (100%) - Installing psr/http-message (1.0.1): Downloading (100%) - Installing guzzlehttp/psr7 (1.4.2): Downloading (100%) - Installing guzzlehttp/guzzle (6.3.0): Downloading (100%) - Installing laravel/installer (v1.5.0): Downloading (100%) symfony/console suggests installing symfony/event-dispatcher () symfony/console suggests installing symfony/lock () symfony/console suggests installing psr/log (For using the console logger) guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware) Writing lock file Generating autoload files
ルート確認
routes
Where view fold?
D:\xampp\htdocs\laravelapp\resources\views か
テンプレートはresource/view にあり、
BladeはシンプルながらパワフルなLaravelのテンプレートエンジンです。他の人気のあるPHPテンプレートエンジンとは異なり、ビューの中にPHPを直接記述することを許しています。全BladeビューはPHPへコンパイルされ、変更があるまでキャッシュされます。つまりアプリケーションのオーバーヘッドは基本的に0です。Bladeビューには
.blade.phpファイル拡張子を付け、通常はresources/viewsディレクトリの中に設置します。
@See https://readouble.com/laravel/5.5/ja/blade.html
@で始まるのがbladeテンプレートエンジンか。
Hell world してみる
Route::get('/', function () {
return view('welcome');
});
Route::get('hello', function () {
return '<html><body><h1></h1></body></html>';
});
おk。
$html = <<<EOF
EOF ;
Route::get('hello', function () use ($html){
return $html;
});
ヒヤドキュメントもOK
ルートパラメーターも可能か。
Route::get(/’hello/{msg}’, function () use ($msg){
$mag に’sample’が代入
);
Route::get('hello/{msg}',function ($msg) {
$html = <<<EOF
<html>
<head>
<title>Hello</title>
<style>
body {font-size:16pt; color:#999; }
h1 { font-size:100pt; text-align:right; color:#eee;
margin:-40px 0px -50px 0px; }
</style>
</head>
<body>
<h1>Hello</h1>
<p>{$msg}</p>
<p>これは、サンプルで作ったページです。</p>
</body>
</html>
EOF;
return $html;
});
パラメータを任意(必須じゃなくするには)
末尾に?をつける。
Route::get('hello/{msg?}',function ($msg) {




