MYSQL在PHP中选择查询

I am new to Laravel and I am trying to receive the clasa_id from the clasa table in the elevi table.

    $clasa = new Clasa();
    $clasa->cifra = \Auth::user()->clasa_cifra;
    $clasa->litera = \Auth::user()->clasa_litera;
    $clasa->save();


    $elev = new Elevi();
    $elev->nume = $request['nume'];
    $elev->prenume = $request['prenume'];
    $elev->clasa_id = ?????
    $elev->save();

Firstly in the clasa table I add the clasa_cifra and clasa_litera, and generate an auto increment clasa_id and I want to make a

select 'clasa_id' from 'clasa' where 'clasa_cifra=\Auth::user()->clasa_cifra, clasa_litera=\Auth::user()->clasa_litera'

and add it to the clasa_id from the elevi table

how to implement it? Thank you!

The best option is to pass the $clasa object in the function where you are creating Elevi::class and use it as:

$clasa->id

If passing object is not an option then you can write query to fetch the corresponding $clasa object as:

$clasa = Clasa::where('cifra', \Auth::user()->clasa_cifra)
        ->where('litera', \Auth::user()->clasa_litera)
        ->select('id')
        ->first()

and you can get the id by using $clasa->id