I am trying to import multiple rows from an excel sheet using Maatwebsite-excel 3.1.
Here, is the challenge, when I do. dd($row)
it prints all the rows. However, the moment I am not running the code without DD, it magically "empties" the rows.
Below is my code
public function collection(Collection $rows)
{
$rows->shift();
$total_amount = 0;
foreach ($rows as $row){
if($row->filter()->isNotEmpty()){
$article_title =collect(trim($row[0]))[0];
$tag = collect(trim($row[1]))[0];
$words = collect((int) $row[2])[0];
$deadline = collect(trim($row[3]))[0];
$pkw = collect(trim($row[4]))[0];
$skw1 = collect(trim($row[5]))[0];
$skw2 = collect(trim($row[6]))[0];
$instructions = collect(trim($row[7]))[0];
$my_tag = UserTag::where('name', 'LIKE', '%'.$tag.'%')->first();
$my_urgency = Urgency::where('name', 'LIKE', '%'.$deadline.'%')->first();
// dd($tag, $words, $my_urgency);
$amount = $my_tag->amount_per_word * $my_urgency->amount * $words;
$project_deadline = now()->addHours($my_urgency->hours)->format('Y-m-d H:i:s');
Project::create([
'user_id'=>request()->user()->id,
'article_title'=>$article_title,
'upload_batch_id'=>$this->batch->id,
'user_tag_id'=>$my_tag->id,
'urgency_id'=>$my_urgency->id,
'price_per_word'=>$my_tag->amount_per_word,
'no_of_words'=>$words,
'deadline'=>$project_deadline,
'amount'=>($amount),
'primary_keyword'=>$pkw,
'secondary_keyword_1'=>$skw1,
'secondary_keyword_2'=>$skw2,
'instructions' => $instructions
]);
$total_amount = $total_amount + $amount;
}
}
$this->batch->amount = $total_amount;
$this->batch->update();
}
I have also used tried it without collect(trim(row[value]))
but this also did not work.
I have tried following these solutions, but none of them worked for me
and below is my dd statement
Please help me kindly.