LoginSignup
0
0

More than 1 year has passed since last update.

compactの使い方

Posted at
UserController.php
public function index()
{
   $user = Auth::user();
   return view('index', compact('user'));
}

$userにログインしているユーザー情報を定義、$を付けずcompactの中にuserと記載し、index.blade.php(ビュー側)に定義した$userを渡す事が出来ます。

index.blade.php
<p>{{ $user->name }}</p>

と記載をするとログインしているusersテーブルのnameカラムを取得し表示する事ができます。

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