Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i have this code for select id from table petugas and have statement where from auth

$petugas = petugas::where('ID_PETUGAS','=',auth()->user()->id);

and i want put that id to this code

Peminjaman::create([
            'ID_ANGGOTA' => $request->ID_ANGGOTA,
            'ID_BUKU' => $request->ID_BUKU,
            'ID_PETUGAS' => $petugas->ID_PETUGAS, --> to this
            'TANGGAL_PINJAM' => $request->TANGGAL_PINJAM,
            'TANGGAL_KEMBALI' => $request->TANGGAL_KEMBALI
        ]);

how to take the input of these variables ?

question from:https://stackoverflow.com/questions/65643137/how-to-make-variable-from-eloquent-select

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
366 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use the first() method:

$petugas = petugas::where('ID_PETUGAS','=',auth()->user()->id)->first();

Then

echo $petugas->ID_PETUGAS;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...