<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Import Export Archives - Codeplaners</title>
	<atom:link href="https://codeplaners.com/tag/import-export/feed/" rel="self" type="application/rss+xml" />
	<link>https://codeplaners.com/tag/import-export/</link>
	<description>Code Solution</description>
	<lastBuildDate>Thu, 20 May 2021 00:15:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>

<image>
	<url>https://codeplaners.com/wp-content/uploads/2020/09/cropped-favicon-social-32x32.png</url>
	<title>Import Export Archives - Codeplaners</title>
	<link>https://codeplaners.com/tag/import-export/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Laravel 8 Import Export Excel File</title>
		<link>https://codeplaners.com/laravel-8-import-export-excel-file/</link>
					<comments>https://codeplaners.com/laravel-8-import-export-excel-file/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 19 May 2021 23:42:27 +0000</pubDate>
				<category><![CDATA[Laravel]]></category>
		<category><![CDATA[Laravel 8]]></category>
		<category><![CDATA[Import Export]]></category>
		<category><![CDATA[laravel 8 Import Export]]></category>
		<guid isPermaLink="false">https://codeplaners.com/?p=778</guid>

					<description><![CDATA[<p>Hello Dev, Today, i we will show you laravel 8 import export excel file. This article will give you simple example of laravel 8 import export excel file. you will learn laravel 8 import export excel file. So let&#8217;s follow few step to create example of laravel 8 import export excel file. Step 1:- Install &#8230; <a href="https://codeplaners.com/laravel-8-import-export-excel-file/" class="more-link">Continue reading<span class="screen-reader-text"> "Laravel 8 Import Export Excel File"</span></a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-8-import-export-excel-file/">Laravel 8 Import Export Excel File</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Hello Dev,</p>
<p>Today, i we will show you laravel 8 import export excel file. This article will give you simple example of laravel 8 import export excel file. you will learn laravel 8 import export excel file. So let&#8217;s follow few step to create example of laravel 8 import export excel file.</p>
<p><img decoding="async" src="https://codeplaners.com/wp-content/uploads/2021/05/laravel8import.jpg" alt="Laravel 8 Import Export Excel File" ></p>
<h3>Step 1:- Install Laravel 8</h3>
<pre class="brush: php; title: ; notranslate">
composer create-project --prefer-dist laravel/laravel importexport
</pre>
<p><strong>Connect Database .env</strong></p>
<pre class="brush: php; title: ; notranslate">
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=databse
DB_USERNAME=root
DB_PASSWORD=
</pre>
<h3>Step 2:- Install maatwebsite/excel Package</h3>
<pre class="brush: php; title: ; notranslate">
composer require maatwebsite/excel
</pre>
<p>Now open <strong>config/app.php</strong> file and add service provider and aliase.<br />
<strong>config/app.php</strong></p>
<pre class="brush: php; title: ; notranslate">
'providers' =&gt; &#x5B;
	...
	Maatwebsite\Excel\ExcelServiceProvider::class,
],

'aliases' =&gt; &#x5B;
	...
	'Excel' =&gt; Maatwebsite\Excel\Facades\Excel::class,
],
</pre>
<p>Then just migrate it by using following command</p>
<pre class="brush: php; title: ; notranslate">
php artisan migrate
</pre>
<h3>Step 3 :- Create Authentication </h3>
<pre class="brush: php; title: ; notranslate">
composer require laravel/ui

php artisan ui bootstrap --auth
</pre>
<h3>Step 4: Create Dummy Users</h3>
<pre class="brush: php; title: ; notranslate">
php artisan tinker
\App\Models\User::factory(10)-&gt;create();
</pre>
<h3>Step 5:- Add Routes</h3>
<p><strong>routes/web.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\MyController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the &quot;web&quot; middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', &#x5B;App\Http\Controllers\HomeController::class, 'index'])-&gt;name('home');


Route::get('excel-csv-file', &#x5B;MyController::class, 'index']);
Route::post('import-excel-csv-file', &#x5B;MyController::class, 'importExcelCSV']);
Route::get('export-excel-csv-file/{slug}', &#x5B;MyController::class, 'exportExcelCSV']);
</pre>
<h3>Step 6:- Create Import Class</h3>
<pre class="brush: php; title: ; notranslate">
php artisan make:import UsersImport --model=User
</pre>
<p><strong>app/Imports/UsersImport.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
    
namespace App\Imports;
    
use App\Models\User;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;
     
class UsersImport implements ToModel, WithHeadingRow
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new User(&#x5B;
            'name'     =&gt; $row&#x5B;'name'],
            'email'    =&gt; $row&#x5B;'email'], 
            'password' =&gt; \Hash::make($row&#x5B;'password']),
        ]);
    }
}
</pre>
<h3>Step 7:- Create Export Class</h3>
<pre class="brush: php; title: ; notranslate">
php artisan make:export UsersExport --model=User
</pre>
<p><strong>app/Exports/UsersExport.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
   
namespace App\Exports;  
use App\Models\User;
use Maatwebsite\Excel\Concerns\FromCollection;
class UsersExport implements FromCollection
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return User::all();
    }
}
</pre>
<h3>Step 8:- Add Controller</h3>
<p><strong>app/Http/Controllers/MyController.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
 
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Exports\UsersExport;
use App\Imports\UsersImport;
use Maatwebsite\Excel\Facades\Excel;
use App\Models\User;
 
class MyController extends Controller
{

    public function index()
    {
       return view('import');
    }
    
    public function importExcelCSV(Request $request) 
    {
        $validatedData = $request-&gt;validate(&#x5B;
           'file' =&gt; 'required',
        ]);
        Excel::import(new UsersImport,$request-&gt;file('file'));
        return redirect('excel-csv-file')-&gt;with('status', 'The file has been excel/csv imported to database in laravel 8');
    }
	
    public function exportExcelCSV($slug) 
    {
        return Excel::download(new UsersExport, 'users.'.$slug);
    }
}
</pre>
<h3>Step 9:- Create Blade File</h3>
<p><strong>resources/views/import.blade.php</strong></p>
<pre class="brush: php; title: ; notranslate">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Laravel 8 Import Export Excel File - codeplaners.com&lt;/title&gt;
  &lt;meta name=&quot;csrf-token&quot; content=&quot;{{ csrf_token() }}&quot;&gt;
  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div class=&quot;container mt-5&quot;&gt;
      @if(session('status'))
        &lt;div class=&quot;alert alert-success&quot;&gt;
            {{ session('status') }}
        &lt;/div&gt;
      @endif
      &lt;div class=&quot;card&quot;&gt;
        &lt;div class=&quot;card-header font-weight-bold&quot;&gt;
          &lt;h2 class=&quot;float-left&quot;&gt;Laravel 8 Import Export Excel File - codeplaners.com&lt;/h2&gt;
          &lt;h2 class=&quot;float-right&quot;&gt;&lt;a href=&quot;{{url('export-excel-csv-file/xlsx')}}&quot; class=&quot;btn btn-success mr-1&quot;&gt;Export Excel&lt;/a&gt;&lt;a href=&quot;{{url('export-excel-csv-file/csv')}}&quot; class=&quot;btn btn-success&quot;&gt;Export CSV&lt;/a&gt;&lt;/h2&gt;
        &lt;/div&gt;
        &lt;div class=&quot;card-body&quot;&gt;
            &lt;form id=&quot;excel-csv-import-form&quot; method=&quot;POST&quot;  action=&quot;{{ url('import-excel-csv-file') }}&quot; accept-charset=&quot;utf-8&quot; enctype=&quot;multipart/form-data&quot;&gt;
              @csrf    
                &lt;div class=&quot;row&quot;&gt;
                    &lt;div class=&quot;col-md-12&quot;&gt;
                        &lt;div class=&quot;form-group&quot;&gt;
                            &lt;input type=&quot;file&quot; name=&quot;file&quot; placeholder=&quot;Choose file&quot;&gt;
                        &lt;/div&gt;
                        @error('file')
                            &lt;div class=&quot;alert alert-danger mt-1 mb-1&quot;&gt;{{ $message }}&lt;/div&gt;
                        @enderror
                    &lt;/div&gt;              
                    &lt;div class=&quot;col-md-12&quot;&gt;
                        &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; id=&quot;submit&quot;&gt;Submit&lt;/button&gt;
                    &lt;/div&gt;
                &lt;/div&gt;     
            &lt;/form&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;  
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Now we are ready to run our project.</p>
<pre class="brush: php; title: ; notranslate">
php artisan serve
</pre>
<pre class="brush: php; title: ; notranslate">
http://localhost:8000/excel-csv-file
</pre>
<p><a style="background: #E91E63;color: #fff;padding: 12px 25px;display: table;border-radius: 7px;margin: 0 auto;text-align: center;" href="https://github.com/codeplaners/Laravel-8-Import-Export-Excel-File">Download Source Code</a></p>
<p>The post <a rel="nofollow" href="https://codeplaners.com/laravel-8-import-export-excel-file/">Laravel 8 Import Export Excel File</a> appeared first on <a rel="nofollow" href="https://codeplaners.com">Codeplaners</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codeplaners.com/laravel-8-import-export-excel-file/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
