LoginSignup
1
0

ログイン中のユーザー情報を取得する方法

Last updated at Posted at 2024-03-19

Laravel単体の時は

$profile = Auth::user();

これで問題なかった。

vueを合わせるために
api.php→コントローラー→vueで受け取り表示
だと上記がうまくいかなくて
以下でうまくいきました。

    public function index()
    {
        // $profile = Auth::user();
        // $profile = Auth::user()->get();
        // $profile = Auth::guard('api')->user()->get();
        // $profile = Auth::guard('api')->user()->get();
        // $profile = Auth::guard('api')->user()->get();
        // →これらはユーザー情報を取得できなかった

        // ⭐️これでいけた
        $id = Auth::id(); 
        $profile = User::where('id', $id)->get();
        return $profile;
    }
1
0
1

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
1
0