I'm facing an issue while uploading csv file with the help of laravel queue jobs. Problem is that when I don't enter some value in csv and it is in the form of ,, I have a check isset($item[10]) which will check if $item[10] has value or not but it is not working actually. It is still submitting in mysql table with value null. I've tried !empty($item[10]) as well as !($item[10]==null) and !($item[10]=='') but not working. Thank you for your kind help.
public function handle()
{
foreach ($this->chuck_data as $item){
if (isset($item[10])) {
bucket_comment::create([
'bucket_id' => $claim_file->id,
'disposition_id' => $dispo_id,
'disposition_name' => $disposition,
'followup_date' => $item[13],
'comment' => !empty($item[10]) ? $item[10] : null,
'bucket_com_create' => Carbon::now('Asia/Kolkata')->format('m/d/Y g:i A'),
'create_date' => Carbon::now('Asia/Kolkata')->format('Y-m-d'),
]);
}
}
}
CodePudding user response:
I think this will cleanup your code.
public function handle()
{
foreach ($this->chuck_data as $item){
$comment = trim($item[10]) ?: null;
//Checking if comment existed on not
if ($comment) {
bucket_comment::create([
'bucket_id' => $claim_file->id,
'disposition_id' => $dispo_id,
'disposition_name' => $disposition,
'followup_date' => $item[13],
'comment' => $comment,
'bucket_com_create' => Carbon::now('Asia/Kolkata')->format('m/d/Y g:i A'),
'create_date' => Carbon::now('Asia/Kolkata')->format('Y-m-d'),
]);
}
}
}