php - Laravel - Excel: Add validation and display the message
one text
We implemented the maatwebsite because in our module there's import capability.
Now I want to add a validation for each column to check if it has a value.
Here's what my import file looks like.
Controller
public function import()
{
$this->validate([
'file' => 'required|mimes:csv,txt|max:3072|file'
]);
Excel::import(new Import, $this->file);
}
Import
public function collection(Collection $rows)
{
$count = count($rows);
// if the uploaded file has 2 or more value
if($count > 1)
{
$array = [];
foreach ($rows as $r => $row) {
//skip the title header
if($r != 0)
{
if($row[0] == '')
{
//display error message
}
}
}
}
else
{
// $this->dispatchBrowserEvent('swal:redirect',[
// 'position' => 'center',
// 'icon' => 'success',
// 'title' => 'Successfully changed filter!',
// 'showConfirmButton' => 'true',
// 'timer' => '1500',
// 'link' => '#'
// ]);
return false;
}
}
Notes: Reason why I didn't use the mapping because there's a condition when the imported file has/have same number it will merge/combine
Question: How can I display the error message?
Source