compact関数
について忘れがちなのでメモ。
Controllerからviewへ変数を受け渡す時に使うのがcompact関数
である。
では以下に例を簡単に記述
Controller/testController.php
public finction test() {
$test = hogehoge;
return view('test',compact('test')); //'test'はviewに変数$testを渡す。
}
'test'はviewに変数$testを渡す。
についてだが
test.blade.php
Controllerから送られてきた変数$testは以下の様な形で記述する。
<p>{{ $test }}</p>
はい、以上!
他にはwithメソッド
もあるけど、割愛。