Seeder in Laravel | Laravel Seeding | Laravel 9 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 all about laravel cedar right so what is cedar actually it is direct related to database right few days back we discussed about the migration so migration is used to create or alter any table right it is related to structure of the database now in cder we used to add some dummy data into the database right automatically or you can insert any records or you can insert any data through the seed the process of adding data into the database is called setting okay so so why we use this seeder right so as a developer you created any application and there is some few records we inserted and we tested that things but we don't know about when we get millions of data or when you get multiple data with the proper relations then what will be means we cannot check our program is optimized or not right so we can insert dummy data with the seeding so the developer can test it also tester can test it right so this is my database there is level 9 database and this is the student statement i want to insert one data into this student table so how you can do this right so before that i'm going to know where actually seeder is present so when you actually install your laravel application this directory is uh getting right so all the serial is related to database so inside the database there is a folder that is seeders folder right so all the seeders actually stored into this theater you can create your own customized seeder and by default laravel provide database seeders actually this is the class database seeder class so it's allowable giving by default right so by default you will get the run method automatically actually when you run your uh seeder that time this run method will call okay and and inside the run method whatever you write it will execute right so first of all we need to learn how to create our custom seeders right so i will discuss about how to run this default heater also and first we will know how to create custom cedar so as we have a table that is students so i am creating a sitter with a student's table name right so let's create another tab and simply let's create a seater so simply php artisan make and the seeder okay and what is the seeder name suppose student table data okay so this is my seeder name so if you just enter this it will create a seeder created successfully and if you check into your directory you will get student table data is added right so this is actually the seeder file it's actually extending the seeder okay and also you will get the run method here also okay so you can write your comment or you can write your query into here so you can write a normal allocant query also you can write your db query you also so all run from here okay no problem on that so inside the student table data i just create a insert query or suppose i am using normal db query there is a reason i am using db here and here sorry the spelling mistake db and here actually we insert some data into the students table so just copy the students table name and simply use this so how we can write this simply use the db i already added into the here and simply write db the table name so what is my table name my table name is students and i will insert some data so simply write insert and take insert array so that inside the array we can write our columns name and data okay so name email phone 8 status there is lots of things okay just write step by step so first of all i am adding a name is suppose sunny okay and the email is suppose email and write your sunny at the rate email.com and simply as for phone and age status okay so let's use phone okay so just add some any random numbers so simply write this okay so this is not actually the number okay so let us remove this and let's add age suppose age is 20 so simply write 20 and status okay so simply status is one okay so all are done this is the insert query now how to run this okay so before running this we need to regenerate our seeder through the autoload so simply just write here composer dump auto load okay so basically it will regenerating the files auto load sorry spelling mistake or to load ok so it is generating the optimized files okay so it's regenerated package manifest generated successfully now you can run your database seeder so simply just copy this to entable seeder and here run php sun db seed and then class name so simply write class and just paste this class name student table seeder so it will you it will see database sitting completed successfully so if you check into our database there is already six records now if i just browse again you can see there is seven records and actually this record are inserted okay now in this way if i have student table seeder teacher tables theater and multiple type of seeder so how we can run in a single comment so using the database seeder we can run multiple seed at a time so we need to register all the seeder into the database seeder and we can run from here also okay so simply just to go to the database seeder this is my default seeder and inside here just simply run [Music] this and we need to use the call function so using call we can call our seeder and as you have multiple series so you can take array so here simply write the student table theater that is the student table data actually this is the class name so just use this and column column class and actually it will run this seeder again via the default see the database seeder so if you have multiple seeder you can add using comma separated value okay no problem on that and let's change some data suppose instead of sunny i am right here rock okay and simply write rock okay and let's change some number that is the random number and instead of 20 i'm using 40 and status is one so now i will not run table data directly i will run the default seeder and it will call us to entable data right now we have a 7 record so if you check and if i just run the default seeder very simply we don't need to write the class name simply use php artisan db and seed okay so it will actually call the seeder so actually one seeder is registered that's the reason exceeding the student table data and if you check inside your application inside your database you will get eight records and this recorder added simple now if you don't want to create any seater you need uh some fused data and want to create different different series simply if you just copy these things and paste it here this will execute actually when you run the php artisan db seed that time run method is working so if you run anything it will run no problem on the so let's try this in your system so if you get any confusion or if you get any problems please comment in the below comment section so next day we are going to discuss about another section or another concept of serial with the faker right so we'll discuss i would actually faker using the faker we can insert multiple data at a time means here we are just writing one data and we are executing seeder and we are getting data into the database using faker we can insert multiple data at a time right so that it will be very easy and with a few seconds we can insert millions of data into your database right so that we can test it and we can check our optimization of our application so please like and subscribe this channel for upcoming video thanks for watching this video have a good day bye
Info
Channel: Learning Points
Views: 8,519
Rating: undefined out of 5
Keywords: How to use laravel seeding?, What is default seeded in laravel?, How to create seeder in laravel 9?, How to create custom seeder in laravel?, How to call another seeder from Database Seeder?, How to call my own seeder directly?, command to create seeder, what is seeder, why we will use seeder, laravel 9 seeder, laravel seader, php artisan db:seed, how to run custom seeder, insert data using seeder, how to insert data using seeder, laravel 9 tutorial, learning points, seeding
Id: HhosfXgTBYw
Channel Id: undefined
Length: 9min 20sec (560 seconds)
Published: Tue Jun 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.