ビューの使い方

まずは sample_app/resources/views/sample.blade.php

というファイルを作成してみましょう。

sample.blade.php

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>はじめてのView</title>
</head>
<body>
    <h1>はじめてのView</h1>
    <p>Viewファイルを利用してHTMLの文字列を返すと、ルーティングのファイル(web.php)がシンプルになります。</p>
</body>
</html>

上記の内容で保存したら、続いてこのviewを利用するルーティングを定義します。

web.php

(上部を省略)
Route::get('/view_sample', function () {
    return view('sample');
});

上記を追記したら、

http://localhost/view_sample

(Docker Toolboxの場合は http://(dockerのipアドレス)/view_sample )

にアクセスしてみましょう。 sample.blade.php の内容が表示されているのを確認できればOKです。

(後始末)

前項で作成した /non_view_sample のルート(HTMLを直接記述)については、後々読みにくくなるので、 ここまでの内容が終わったら削除しておきましょう。

results matching ""

    No results matching ""