How to Import Excel CSV File in Laravel | Laravel 8 Excel Import | Laravel Excel Import to Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello and welcome to tech tool india in this video i will explain how you can import any data from excel or a csv file into your database before starting if you are new to the channel please do subscribe our channel so without wasting any time let's get started in this video i am going to use laravel tech admin panel if you want to install this panel you can get a link of github repository for this in the description you can install this or you can click on the i button to see the installation steps for this panel so let's login to this we already have a user management where in this page we are listing all the users in the database so i have created as example sheet where i have just entered few details like first name last name email and the mobile number and i just want to import all these users into our user list so for this what i'm going to use i'm going to use laravel excel so laravel excel is a package for laravel by using this package we can import or export excel into laravel what i'm going to do now i'm simply going to install this in our project so installation is very simple just we just need to install it through the composer so i'll just write it down like composer require let's install this so as you see this package is installed in our system let's go and see what next we need to do this package is auto discovered so we don't have to register this the aliases are also auto discovered to publish the config run this command to publish the config file so let's run this command and see what we get if you see inside a config we have excel excel.php file which has all the configuration related to the excel file so we have installed the package let's see how we can import the data so as per the documentation what we need to do we need to create a class in apps last imports so we can do with the by using a php artisan command as in this video we have to import users so let's copy this command and paste it in our terminal so let's open the app folder you see there is a imports folder and user import class is already there so what we need to do next we need to define the field name based on the rows position in the excel file so in this user import file we need to define the fields which we are taking from csv or excel file to the field name which we want to import into a database so let's see the exceed what we have in our sheet we have a first name field let's take it and calling it row for the first name similarly i'm going to copy paste this and the second is last name third one is email fourth one is mobile number the next which i am going to use as we have implemented role here so what i'm going to assign role and status one one and one is for user one for admin two for users so for role all these users having role id to which stand for user type user and the next which i going to define is status is one for everyone and for password you can use any common password i'm just going to use a common password called password so by this we have selected all the first name row names from the excel file to the field name of the table so let's define our roots i have written two roots for importing user one is for a view page which is import user which actually loads the page where we can select a file and upload the data so this page is loaded by this root and for this import user function if you see this import user function in the controller what it has it actually returns this view for the import so by this you can select a file now let's come into the upload user when you submit that form it comes to upload user what we are using here we are just using the excel facade provided by the excel package level excel package we are just giving this a user's import class and we are passing the file so everything is handled inside this excel user import what we have written so here we have already defined it is coming the file is with the headings and it it is going to use all the heading with the name and based on that it is going to you know create a user role and based on this is going to assign a role and from here it will return a user model so all set let's go ahead and select a file and upload it on a database we have our table here let's go to the import data let's select the user x csv file let's click on upload as you see it has uploaded all the users mentioned here in the data sheet at once you see all the rows everything is there so it's quite easy i hope you understand how you can use laravel excel to upload any number of data into your database if you found this video informative please do subscribe our channel keep learning thank you for watching [Music] you
Info
Channel: TechTool India
Views: 31,558
Rating: undefined out of 5
Keywords: laravel excel import, laravel, laravel excel, laravel 8 tutorial, laravel import excel to database, laravel 8, laravel excel export example, laravel excel export, how to import export excel in laravel, excel, laravel import excel, import excel, laravel excel import to database, laravel import excel file to database, laravel 8 import export excel & csv file, laravel excel import export, laravel export table to excel, export excel and csv in laravel
Id: -h2wpwATsXw
Channel Id: undefined
Length: 7min 28sec (448 seconds)
Published: Sat Feb 12 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.