0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

★compactの使い方

Posted at

参考記事


compact関数はPHPの関数。(Laravel独自関数ではない)
Laravelでcompact()を使う場合、ControllerからViewに値を渡す際に使われ、表記を短縮できる。
変数名と配列キーは同じ表記になるため、タイプミスを減らせるというメリットもある。

A.compact()なし

return view('list', ['products'->$products, 'companies'=>$companies])
$user = [ 'name' => 'example',
          'email' => 'example@email.com',
          'address' => 'ExamplePrefecture'
        ];

B.compact()あり

return view('list', compact('products','companies'));
$name => 'example',
$email => 'example@email.com',
$address => 'ExamplePrefecture'

$user = compact('name','email','address');

終わり👋

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?