简体   繁体   中英

laravel mysql to query builder

i'm relatively new to laravel and i'm having issues when trying to convert this function to laravel's query builder. This is the function i've been given which also runs a python script to decrypt the database.

Using the documentation from laravel.com you can do something like this:

function call($unitId)
{
    $pfContact = DB::table('PFContact')
        ->where('UnitID', $unitId)
        ->latest() // Order by created_at
        ->first([ // Only retrieve these columns
            'Send',
            'Receive',
            'Core',
            'lock'
        ]);

    $pfReadings = DB::table('PFReadings')
        ->get();

    $rowCount = $pfReadings->count();

    foreach ($pfReadings as $i => $reading) {
        echo $i < count($reading) / $rowCount;
        foreach ($reading as $column => $value) {
            echo shell_exec(
                'python3 enc.py ' . $value 
                . ' ' . $pfContact->Send 
                . ' ' . $pfContact->Receive 
                . ' ' . $pfContact->Core 
                . ' ' . $pfContact->lock . ' ' 
                . $unitId . ' l'
            ) . '~';
        }
        echo ';';
    }
}

And although I do not know what arguments this pyhton script needs you should really think this through. Why would you use PHP for this and not just handle everything from the python (or php) side because this looks over complicated to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM