your form element needs enctype="multipart/form-data" to allow file upload
Mar 15, 2016
4
Level 7
uploading CSV
View:
@extends('layouts.suplayout')
@section('content')
<h1>CSV Upload</h1>
@include ('errors.list')
{!! Form::open(array('method' => 'POST','url' => 'uploadexcel')) !!}
<div class="form-group">
{!! Form::file('file') !!}
</div>
<div class="form-group">
{!! Form::submit('Add', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
@stop
controller method:
public function csvupload()
{
return view('superadmin.csvupload');
}
public function upload()
{
$rules = array(
'file' => 'required',
//'num_records' => 'required',
);
$validator = Validator::make(Input::all(), $rules);
// process the form
if ($validator->fails())
{
return Redirect::to('sales')->withErrors($validator);
}
else
{
try {
Excel::load(Input::file('file'), function ($reader) {
foreach ($reader->toArray() as $row) {
sales::Create($row);
}
});
\Session::flash('success', 'Sales uploaded successfully.');
return redirect(route('sales'));
} catch (\Exception $e) {
\Session::flash('error', $e->getMessage());
return redirect(route('sales'));
}
}
}
routes:
Route::get('superadmin/csvupload', 'SuperAdminController@csvupload');
Route::post('uploadexcel', 'SuperAdminController@upload');
I am doing the above and uploading a CSV however when doing so it brings no errors nothing anyone know why this is happening or how to fix this??
Edit:
Just found this in the debugbar: error Could not open for reading! File does not exist. For some reason my errors aren't popping up weird , anyone know why it cant read it?
Please or to participate in this conversation.