Tutorialsplane

Laravel Import Data from CSV to Table


Laravel Import Data from CSV to Table – The Laravel Import Data from CSV to Table is used to import file to CSV to table.


Laravel Import Data from CSV to Table | with full Example.

Let us understand how to use Laravel Import Data from CSV to Table.

Full example of Import Data from CSV to Table.

Now here i am going to explain how to Import Data from CSV to Table.

First we have to create controller page and save as [ImportController.php].

Let’s look at a simple example.

<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use App\TestModel;
//use App\Excel;
use Excel;

class ImportController extends Controller 
{
	public function upload()
	{
		return view('Import');
	}
   public function ImportClient()
	{
		$file = Input::file('file');
		$file_name = $file-?>getClientOriginalName();
		$file->move('files', $file_name);
		$result = Excel::load('files/'.$file_name, function($reader)
		{
			$reader->all();
		})->get();
		return view('Import');
	}
}

Then create a view page and save as [Import.blade.php]

Let’s look at a simple example.




    <title>Laravel Import example</title>
    


Route Path:-

Route::get('/Import','ImportController@upload');
Route::post('/import1','ImportController@ImportClient');

Laravel Tutorial