-1
クーポンを適用しようとすると、私はこのエラーを受け取りました。私はスクリプトの作成者ではありません。私はそれを実行しています。致命的なエラー:ヌルのメンバー関数unique()への呼び出し
このコード
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,
];
}
}
}
}
これは私が
ERROR: Symfony\Compo nent\Debug\Exception\FatalThrowableError: Fatal error: Call to a member function unique() on null
$ parts変数が0になっています – Matheus
'validate_coupon_from_db()'を呼び出す前に '$ parts'をチェックしてください。どうやら、あなたは期待しているCollectionオブジェクトの代わりにnullを送信しています。 – Robert
どのようにすればいいですか? –