Upgrade to Pro — share decks privately, control downloads, hide ads and more …

はじめての実践Laravelでつまづいた話

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for tashiy tashiy
October 07, 2019

 はじめての実践Laravelでつまづいた話

Laravelを業務で初めて使ったログイン認証についてです。

Avatar for tashiy

tashiy

October 07, 2019
Tweet

More Decks by tashiy

Other Decks in Programming

Transcript

  1. Controller処理内容 // LoginController.php // 認証用のカスタム関数 (POST値を受け取る。ユーザー IDからIDのみを抽出) public function authenticate(Request

    $request) { $userid = $request->user_id; if (isset(User::where('user_id', $request->input( 'user_id'))->first()->id)) { // 認証成功時、ユーザー IDからIDを取り出す。 $user_id = User::where( 'user_id', request->input( 'user_id'))->first()->id; $id = Auth::loginUsingId($user_id); return redirect('/home'); } }
  2. IDのみで取得する内容 User::where('user_id', $request->input('user_id'))->first()->id; $id = Auth::loginUsingId($user_id); 公式ドキュメント(英語) Authenticate A User

    By ID To log a user into the application by their ID, you may use the loginUsingId method. This method accepts the primary key of the user you wish to authenticate: Auth::loginUsingId(1); // Login and "remember" the given user... Auth::loginUsingId(1, true);