0
0

More than 3 years have passed since last update.

※メモ※【Laravel5.5】compact関数

Posted at

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メソッドもあるけど、割愛。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0