-1
當我嘗試應用優惠券時,出現此錯誤,我不是腳本的創建者,我只是使用它,我需要幫助來運行它致命錯誤:調用成員函數unique()null
此代碼
private function validate_coupon_from_db($parts){
$parts = $parts->unique('code');
$model_codes = $parts->pluck('code')->all();
$existing_part = Part::whereIn('code',$model_codes)->where('date', '!=', '0000-00-00 00:00:00')->orderBy('created_at', 'desc')->groupBy('code')->get();//->where('date', '>', \Carbon\Carbon::now()->addHour(2))->get();
if($existing_part->count() < $parts->count()){
return [
'status' => 100,
];
}else{
//$part_not_valid = $existing_part->where('date', '<=', \Carbon\Carbon::now()->addHour(2))->all();
$part_not_valid = $existing_part->filter(function ($item) {
return strtotime($item->date) < strtotime(date("Y-m-d H:i:s", strtotime('+2 hours')));
});
if($part_not_valid->count() > 0){
$part_not_valid =$part_not_valid->all();
$string = '';
foreach ($part_not_valid as $part){
$string .= '<br><hr><span> '.$part->code .' '. $part->part_one_name .' - '. $part->part_two_name .' </span>';
}
return [
'status' => 0,
'data' =>
'<div id="s_w_PC_cCoupon_pnlMsgIns" class="divCouponError" style="background-image:url(//static.planetwin365.com/App_Themes/PlanetWin365/Images/ErrorTypes/Errors.png);">'.
'<span id="s_w_PC_cCoupon_errMsgIns"><span>Les côtes suivantes ne sont plus disponibles:</span>'. $string .'</div>'
];
}
else{
return [
'status' => 1,
];
}
}
}
}
這是我在功能validate_coupon_from_db第一行後
ERROR: Symfony\Compo nent\Debug\Exception\FatalThrowableError: Fatal error: Call to a member function unique() on null
$ parts變量爲null – Matheus
在調用'validate_coupon_from_db()'之前檢查'$ parts'。顯然你發送null而不是它期望的Collection對象。 – Robert
我該怎麼做,你可以重寫代碼,因爲我應該 –