Hello,i'm trying to validate a date before import the infos to the database,i need to check if there's a date above today in the file but for some reason(might be a stupid mistake) my foreach loop only check the first index of the array and not all of them,i've searched everywhere for a solution but i couldn't find anything...
My import function:
public function Import(Request $request){
$count = 0;
$today_carbon = Carbon::today()->toDateString();
$request->validate(['file'=>'required|mimes:csv']);
$file = $request->file('file');
$spreadsheet = Excel::toArray(new UserImport,$file);
foreach($spreadsheet as $p){
foreach($p as $i){
$count++;
$columns= count($i);
$date_file = $i[2];
if($today_carbon >= $date_file){
Excel::import(new UserImport,$file);
return redirect('form')->with('success','ok');
}else{
return redirect('form')->with('erro','error');
}
if($columns == 3){
Excel::import(new UserImport,$file);
return redirect('form')->with('success','ok');
}else{
return redirect('form')->with('erro','error');
}
}
}
}
my import model function:
public function model(array $row){
return new User([
'name' => $row[0],
'email' => $row[1],
'sell_date' => $row[2]
]);
}