bladeテンプレート学習の準備

では、実際に確認するための

  • ルーティング
  • コントローラーにアクション作成
  • 元となるテンプレート作成

までを行なっておきましょう。

まずはルーティングを設定します。 web.phpに

web.php

(略)
Route::get('/blade_example', 'SampleController@blade_example');

として追記を行なってみましょう。

続いて、コントローラにアクションを作成します。

sample_app/SampleController.php

(略)
    public function blade_example(){
        $title = 'bladeテンプレートの様々な機能';
        $num = 10;
        $messages = \App\Message::all();
        return view('blade_example',[
            'title' => $title,
            'num' => $num,
            'messages' => $messages,
        ]);
    }
(以下略)

上記のアクションを追加しておきましょう。 そして、今回利用するbladeテンプレートのベースを作成しておきます。

blade_example.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>{{ $title }}</title>
</head>
<body>
    <h1>{{ $title }}</h1>

</body>
</html>

results matching ""

    No results matching ""