Laravel 基本 01 インストールから基本

  • 2018年1月19日
  • 2018年1月22日
  • Laravel
  • 31view

そろそろ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) {

 

 

最新情報をチェックしよう!
>最強のWordPressテーマ「THE THOR」

最強のWordPressテーマ「THE THOR」

システムの構築・保守運用「   」 社内システム担当が欲しいが、専属で雇うほどの仕事量はない。 必要な時に必要なだけ頼りたいというお悩みを持つ企業様へ専門知識を持って対応を行っております。 サーバから各種システムまで自社・他社で構築されたシステムに対してサポートを行っております。

CTR IMG