sb2g14 / soton_3D_print

3 stars 0 forks source link

showing last used by breaks down if the printer hasn't been used yet #67

Closed GHLasse closed 6 years ago

GHLasse commented 6 years ago

If printer has not been used yet, loading the issues page for that printer results in an error for

$lastPrint=$printer->prints()->orderBy('updated_at', 'desc')->first();
$lastJob=$lastPrint->jobs()->first();
if($lastJob->requested_online == 0){
    $lastUser = $lastJob->customer_name;
    $lastUserEmail = $lastJob->customer_email;
} else {
    $lastUser = $lastPrint->staff_started->first_name.' '.$lastPrint->staff_started->last_name;
    $lastUserEmail = $lastPrint->staff_started->email;
}

because $lastPrint will be null should instead be

$lastPrint=$printer->prints()->orderBy('updated_at', 'desc')->first();
if($lastPrint){
    $lastJob=$lastPrint->jobs()->first();
    if($lastJob->requested_online == 0){
        $lastUser = $lastJob->customer_name;
        $lastUserEmail = $lastJob->customer_email;
    } else {
        $lastUser = $lastPrint->staff_started->first_name.' '.$lastPrint->staff_started->last_name;
        $lastUserEmail = $lastPrint->staff_started->email;
    }
}else{
    $lastUser = "--";
    $lastUserEmail = "";
}
GHLasse commented 6 years ago

This issue is back again in the latest version. I guess someone overwrote the changes when merging. The same fix will work again though :-)