0

I am developing a system in which can upload a CSV file and view it in an HTML table. After uploading CSV file saves in the database with an id, but I can't read that CSV file and view it in the HTML table. I want to read the CSV file into an array and then view it in the table. Please help me. It will be a great deal.

Controller files:- projectController

<?PHP
class ProjectController extends Controller
{
 public function index($id)
{
    $project = Project::find($id);
    $data = array();
    // read the CSV and assign the data to $data
    return view('home')->with('project', $project)->with('data', $data);
   }
  }

uploadFileController

public function index()
 {
  return view('/');
 }
public function upload(Request $request)
 {
  $file = $request->file('csv');

  $project = new Project();

  $project->name = $request->name;

  $project->save();

  print_r($file);

  //Move Uploaded File
  $destinationPath = 'uploads';
  $file->move($destinationPath, $project->id . '.' . $file->getClientOriginalExtension());

  return redirect("/project/{$project->id}");
}

This is how it looks:https://i.stack.imgur.com/yosHN.jpg

Perera
  • 21
  • 5
  • try this https://docs.laravel-excel.com/3.1/imports/basics.html – Kamlesh Paul Dec 03 '20 at 09:02
  • This question has been answered here: https://stackoverflow.com/questions/9139202/how-to-parse-a-csv-file-using-php – WoodyDRN Dec 03 '20 at 09:03
  • Does this answer your question? [Read a .csv file into an array in Laravel](https://stackoverflow.com/questions/40136331/read-a-csv-file-into-an-array-in-laravel) – Shibon Dec 03 '20 at 09:04
  • @Shibon Yes it does but how to enter this array into the HTML table.? – Perera Dec 03 '20 at 10:57

0 Answers0