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

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

laravel - how to make variable from eloquent select

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

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

1 Answer

0 votes
by (71.8m points)

Use the first() method:

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

Then

echo $petugas->ID_PETUGAS;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...