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?

More than 3 years have passed since last update.

ログイン時のデータ取得について書いてみた

Posted at

ログインしている人がフォームで何かデータを入力することが多いと思いますががそのデータ入力時に
ログインしている人のidも取得したいと思うことがある。そんな時のやり方がわからなかったので
ここに忘備録として書いておきます。

 <form method="post" action="{{route('post.store')}}">
 @csrf

 <input type="hidden" id="user_id" value="{{Auth::id()}}">

 <textarea name ="message"class="form-control" id="exampleFormControlTextarea1" 
 rows="3"></textarea>
 </form>

type="hidden" を使うことでフロントには表示されずにフォームに登録することができます。
また、value="{{Auth:id( )}}"とありますがこれは今現在ログインしている人のidをフォームに入力しているという意味になります。

いやー。Auth::idの書き方を知らなかったので解決するのに1日かかってしまいました。
基礎がしっかりしていないと大変な目に遭いますね。これでみなさんも
ログイン時のid検出の仕方忘れた場合は利用してみてください。

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?