Laravel Faker Class | How to use laravel faker inside seeder | Laravel Tutorial | Learning Points

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello friends welcome back to laravel 9 tutorial in this video we are going to discuss about another interesting topic of laravel which is to insert some demo data into your database that is a faker all right so the last video we discussed about cedar so how we can insert data into the database so i inserted some data into the students table using seeder so actually if you check into your application inside this database folder you will get theaters folder and you will get database seeder and the student table seeder you will get the database cedar actually i created student table data that is the another seed right so you can say it is an extended part of previous video in this video we will going to discuss about the faker actually what is faker when testing your application for a tester team they need huge data to check how optimized your application is right so that time you need some data and you need some proper data to test a proper optimization of your application so using faker we can insert a huge number of demo data within a few seconds right so how we can do this so using seeder we inserted some data right and now i will insert uh at a time multiple data suppose i want to insert hundreds of data at a time so how we can insert this so that time we can use faker so for faker actually we need to use the faker class so actually this is the figure class use faker slash factory so this is the faker factory factory yes this one okay and use faker so just as faker so i am taking as a faker okay so faker is declared and we are using db so i inserted one data at a time so now i am going to create a multiple data that is i am going to insert hundreds of data right so let's take a variable that is faker equal to let's say use the faker create function and just write faker create so this is the function to initialize the faker and here i just want to insert the for each loop and here simply write for each and i want to insert at a time hundreds of data so i am setting the range from 1 to 100 okay so that will insert the 100 record as index okay and inside here i just need to add this part okay so that will actually come into the loop but using faker we can create a real-time data means a lo it looks like a real data right so simply just use faker name okay so that will create a fake name into your application also you can write a faker email okay and for phone we can write anything like simply just use a random number a random number you can use a faker number also no problem on that i want to insert random number like from one two three four five six seven eight nine ten and one two three four five six seven eight nine ten means our phone number will be length of 10 and the number between this range right and another for age i can set a range between 1 1 2 9 9 okay no problems so that will be the two digit number okay and status by default i am taking as one no problem on that and now uh if i just run this uh faker so if i just run the seeder that time this faker function will call so simply just to go to the terminal and just run php rotation db set okay so actually when you call the dbc it actually that file will call and from inside the database seeder i am setting these things that is the i will call in the student table data actually this one is the student table data and this will call so there's a reason it will run okay now just to run this so what is the error numeric value out of range one two six four out of range form yes something missing in phone so let's make it some small okay so i may have a length is a small in the um database okay so let's run this again so ceiling so database sitting completed successfully so if you now just uh go to the browser and let's check so currently we have eight records so i should have 108 records okay so we are getting 180 records and if you check these are the uh looking real-life data right uh mr jamie and this is the email and these all the things are generated that is the age is the phone number all randomly generated okay so you can understand how first we can insert the demo data for our testing purpose or to test the optimization of your application so this is the important concept and you need this when you're actually project is developed and going for test all right so this is all about faker this is nothing much in faker and the next day we are going to do one thing we are going to create a list of all the students and we will use a blade template so as a laravel using the blade template so i want to show you the proper list of all students with a proper pagination okay so next day we will going to discuss about that thing so we designation and how to render data from controller to view right so that will be the important things right so hope you like this video and still if you have any queries about faker please comment below comment section and please like and subscribe this channel for upcoming video thanks for watching this video have a good day bye
Info
Channel: Learning Points
Views: 3,495
Rating: undefined out of 5
Keywords: How to use faker class in laravel?, How to use faker class inside seeder?, How to insert fake data into laravel?, Insert test data inside laravel, faker with seeding, laravel 9 faker class, laravel 9 faker with seeding, laravel faker, insert test data with faker, faker class, laravel tutorial, laravel 9 tutorial, learning points, latest technology, php framework, laravel for beginner, latest laravel, use of faker class, how to run faker to database, insert data with faker
Id: WPh7qAiWobs
Channel Id: undefined
Length: 6min 30sec (390 seconds)
Published: Wed Jun 15 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.