mardi 21 juillet 2020

Laravel Eloquent select where latest equal to value

I have two MySQL tables, the second table recorded the states of an attribute of the first table, I need to get all the records of the first table where the last state of the attribute is equal to value, how to do it with eloquent ?

here is my code that I need to add the condition to :

function getMaterielForAff(Request $request)
{
    $data = Materiel::join('Types', 'Materiels.type_id', '=', 'Types.type_id')
            ->join('Users', 'Materiels.user_id', '=', 'Users.id')
            ->join('Journal_etat_materiels', 'Materiels.mat_code', '=', 'Journal_etat_materiels.mat_code')
            ->select(
                'Materiels.id',
                'Materiels.mat_code',
                'Materiels.mat_designation',
                'Materiels.mat_ns',
                'Materiels.imei1',
                'Materiels.imei2',
                'Types.type_designation',
                'Materiels.mat_description',
                'Materiels.mat_carac',
                'Materiels.note',
                'Users.username',
                'Materiels.mat_date'
            )
            ->whereNotIn('Materiels.mat_code', explode(' ', $request->mat_codes));

    return DataTables::of($data)
        ->addColumn('check', function ($check) {
            return '<input type="checkbox" required="required" name="check" class="check" id="' . $check->id . ' value="' . $check->id . '">';
        })
        ->rawColumns(['check'])
        ->make(true);
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire