Laravel CRUD in 50 minutes for Beginners from Scratch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video I'm going to teach you how to implement crud operation in laravel for beginners okay let's talk about the development tools that we are going to use we are going to use composer Sam Visual Studio code and if you don't know how to install laravel on your computer I will put the link in the description so you can check it out about how to install the development tools as well as how to install laravel alright let's talk about crowd operation so when we talk about Crash operation we refer is to four basics function that interact with database such as trade read update and delete data from database all right what you will learn from this tutorial you will learn quad operation you will learn blade template in laravel and then you will learn Basics eloquent alright the next thing I want you to know is laravel MVC architecture so we are going to use this diagram to code so it's going to be very easy for you to understand the whole process alright let's get started all right first step let's go to laravel website laravel.com then go to documentation and make sure you are in installation okay scroll down we have to copy this code to install laravel on our computer by using composer PC and then let's go to drive C and then let's go to xam and then go to htdocs okay okay then press shift and right click over here click on open Powershell here paste the code over here example app over here you can remove it so you can name is whatever you want but in this case I'm going to name is app crud okay and then larva will be download and installed in our computer after the installation is done you can close the Powershell and you will see the app Cloud folder over here and then you can drag and drop these folders to visual studio code to open the projects with Visual Studio code okay you will get something like this and then let's go to terminal over here new terminal type PSP Artisan serve to run laravel application hit enter and then you will get this URL you can copy this URL and then paste it on web browser hit enter see this is our application is running next step we are going to create database for our application okay let's go to phpmyadmin go to localhost PHP my admin okay or you can go to Sam over here and just click over here admin so let's click news over here I'm going to name the database as same as the application name so I name is app crud Okay click on create so we have the application name over here so we can copy the application name or remember it and then we go to our projects and then we go to dot EnV and over here and if you have set the password for your database over here you have to set the password over here for me I haven't set any password for the database so I'm going to leave this empty and the database name over here you have to change is from laravel to app dash crud okay save it so to check if our application can connect to the database we can run PHP Artisan migrate okay let's create new terminal over here see you can you have two two terminal right now the first one is PSP Artisan serve which is used to run our application and this one we can execute uh laraville command over here or PSP art design command over here for example I'm going to check if our application is connected to database so I can type PHP artisan migrate hit enter see if the migrate is successfully done like this that's mean our application can connect to database and if you click on the database over here you will see many tables have been created over here these tables are default tables for laravel the next step we are going to create a table for our application in laravel we don't create a table from PHP in my admin we don't create a table from here so in state we use a migration files to generate a table for us so if you go back to laravel documentation and search for migration database migration over here okay and then you go to generate migration this is how you create a table in letterville all right let me show you if you list if you take a look at laravel MVC architecture over here we are in this step create database all right and let's go back to our application we are going to use this command to create a table for us you can copy the command MPS is over here this is the name of the files that we will use to generate a table we can remove this one and we can name it like create products table okay and we hit enter and if you go to a database and go to migrations you will see create products table files have been created okay this is how you put column in the table and if you want this column to contain string you can put table string and then you can put column name for example over here I will put like name and then if you want to create another column you can put table and if you want this column to contain full number or whole number you can put integer and then put the column name I can put qty and then if you want this column to have long text you can put text and this one can be description or if you want this column to contain a decimal you can put table decimal and then you can put price okay where can I get this one from decimal integer string I get this from documentation so when you go to documentation you scroll down and you go to available column type this is the type test column you can use in letterville okay here is decimal here is text string and blah blah okay let's go back to the code after you have this one prepare the next command we have to run to generate this table is PSP Artisan migrate hit enter see if we run the migration files and create table for us you see it's done over here okay if you go back to our database and you refresh you will see product table has been created so far we have learned how to create a table in letter view if you want to create others tables you just do the same step you start from create a migration files then put the column in the files and then type PSP Artisan migrate to generate a table okay here is so simple let's go back to our MVC architecture over here we already have database we have table in database so the next step we are going to create model for products okay we are going to this step okay let's create a model in laravel when you create model you also use a command to create a model so if you want to know how to create model you can go to documentation go to eloquin and then go to get started getting started in eloquent and you scroll down you will see how to generate model class over here okay we can copy this one or you can type it directly on the command line over here I'd like to copy and paste because it saves a lot of time let me copy it again okay paste it over here we are going to name the model relate to the table name over here we are going to name its product so it must be singular okay hit enter and you go if you go to model if you go to app over here model UBC product module has been created over here okay we are going to learn how to manage product table over here you declare protected okay and then fillable equal to array are infillable we are going to put the column name that we want user to input information into the database for example in product we have this column name like name qty price and description this one is auto generate and this one is auto generates as well so in fillable we put column over here name okay and then we put qty and we put price and we put description okay make sure these columns match to these columns we have model right now let's go back to our PowerPoint the next step we are going to create controller okay let's create controller for this product okay we are going to use command line to create model as well let's go back to here and let's see if there is controller over here let's search for controller okay okay controller is in Basics controller this is how you generate controller okay you can copy this command and then scroll back to here and put this over here and then we can put this product controller so it starts with uppercase and then controller is uppercase as well just hit enter okay we have controller right now if we go back to app and then go to http and then go to controllers you will see product controller has been created over here all right we have controller files right now and if we go back to PowerPoint we will see that route interact with controller and view also interact with controller we are going to create a view first and then we are going to create route okay to create view we go to resources and then go to view okay let's put over here let's create a folder over here this name is products okay and then let's put index.blade.php so we have view we have our first view which is index dot delete.php I can generate HTML over here and then I can put like H1 and I can put this product and over here I can create div and I'm going to name it uh index okay so we have view right we are going to create route so how to create route for this page we go to our route so route over here and in web here so let's create our first route together okay over here we put route and the request type we just get and over here we put the URL of the route for example over here I put route product and then we put a controller over here are the controllers that we are going to use is product controller we have create product controller before here we can copy this one and put this over here and then we have to specify this one class and next we have to put a controller function over here and we have to name this route okay you can name is whatever you want but over here I'm going to name is product index okay so we have this route next step we are going to create a function in controller so these functions should be public function Index right so this index we can put in here so this mean index paste when somebody access this route right they type products they type this URL they type you this URL so when they type this URL is go to route then route past the information to product controller class which is over here and is tell that this request must go to index function which is over here an index function is in controller you see index function is in controller index function view return view out to user because the index doesn't connect to database right now okay let's return view out return view our view is in product folder and then index over here okay in route in web here you have to import this one up here so I can put juice so I go to product controller I can copy this one namespace and I put this over here and then I choose a product controller over here so yeah this should be good all right let's go back to web browser let's try our first route yeah product see this is this raw product the URL yeah product okay we hit enter it's go to product and index uh this field okay products index all right we have successfully create index page Next Step let's create other page for example I want to create a create page to create data into database okay we go to Route okay we just copy this route okay then we change is to product and then create okay URL for create page and then over here I put create and this one I put product create and eBay price control over here and I click here it's go to uh product controller and over here I create public function create okay and in create I return View products folder and create so I haven't created this field yet okay I go back to view a resource View and product over here let's create new files and then create Dot blade.php okay let's generate HTML and then put H1 and then create a product save let's go back to our route see if follow the same step create a route and name the path and then specify function in controller and in controller product controller we return view out okay let's go back here and type create over here hit enter we have created a product page let's create a form over here in create let me close this one in create that blade let me close this one this one and this one save and over here let me create form okay because we want to insert data into database so we have to create a form so in form over here I put method it should be post and then action we're going to leave is empty right now and let's create a div over here and then put input type name okay uh name it can be name okay and placeholder input name over here I can put label I can put here its name okay let's take a look at our web browser refresh this page we have name over here right and then let's copy this one to save our time we have uh can be qty this should be qty a type should be oh this type should be string should be text sorry and this one should be text and this one qty name paid holder is QT by quantity and this one is price this one is just only simple HTML okay and this one is text and price page holder should be priced let's machine this one to uppercase and what else we need a Pro qty price and description okay description okay this one and Page holder should be description okay we need a button to submit these files so we can put then we put input type submit okay and value save a new product machine this one to be application okay let's go back here okay we get a form over here so it's not look good because uh this one we don't focus on UI we forget only how MBC in laravel work okay in this step we have UI in order to send data to save in controller yeah we need to have a route for this submit form okay we go to web here and create another route we can copy the from the last one and here is create right this method is post so over here we change method to post and this one we can remove this one we can put like products and this one I will name function in controller store okay we used to store product and this one is store name okay let's go back to product controller over here let's create a function public function store okay this function store is here okay and I'm going to dump the data out so the store actually over here we will accept request from this form so we put a request over here okay and request yeah make sure that your application import this request okay and then we can put request over here you can dump requests out in create over here we have to specify the URL or the route yeah action here you just put route and then we just name the route here this route product store copy it and put it over here sorry and put it over here okay and the next thing that you have to put for security purpose you just put uh add and then c s r f and you have to put method over here as well post save it and if you go back in refresh and if you put name for example Apple two price is 2.2 and description rate Apple and if you save a new product you see I'll request data is over here we have parameter we have uh post method we have a name we have qty we have price we have description so we can access this data in controller over here for example if you want to show name you can put name like this special only name let's refresh this one continue it will show only Apple okay this is how we access data from phone in in controller okay let me remove this one so let's do some simple validation first before we store data into the database okay we put data over here you put request and then we put Barry date and we want to vary that name we put name over here and then you put require and what else we need user to input everything exit description okay we put qty and then uh price okay required this one has to be number okay let's go to documentation and search for validation method so we can learn it together validate so this is how you validate data okay here this is the validation rule that you can use we can use numeric okay numeric and what else we can use decimal okay this one needs to be decimal okay we can save it and then let's store this data to database so in order to store data we are in controller right now right in order to store data in database we have to make it through model so let's import module over here so we want to use our model what model we want to use product model let's copy this one and then import is over here use app model and then product okay we have product over here we can copy it and then over here we just put no product and then product okay we call product model this this model okay because we want to save data to database we have to make it through model so what we want to do create and we just pass in data into this model and we it will be saved into database automatically so when is safe the data into database what we want is to do V1 is to redirect to the index page so let's return redirect to index page so to route and it's to product dot Index this is the name of the index page route okay save it should be good I think so let's go back here let's go back here and then let's save a new product so the validation rule decimal required at least one parameter okay I don't know what's wrong with this one let's go to documentation and click on decimal or when you specify decimal you have to specify uh the Min and Max okay all right let's uh specify the decimal over here okay double colon and let's put two over here save and let's go back over here and let's save a product okay let's take a look at database localhost PHP my admin and then go to appcard products or we don't see data I don't know what's wrong let's go to Apple to 2.22 and description blah blah blah save okay we know what's wrong with this description does have default value oh over here I think I forgot to specify the description here let's specify description over here description and this one we can put like nullable okay let's save okay let's go back here let's save a new product again save C is redirect to product page so if you go to database and refresh the database you will see it's a product in the table product right now okay if you want to save more product for example we go to create page and we put orange and you put qty2 and price is 3.1 and description yellow orange save [Music] um what's happening it doesn't work so I want is to show Eller when it doesn't work so let's go back here and let's go to index here and let's go to create page and over here if there is error okay I want to show is over here so let's put add if so Aller any then we have to put add in if over here if there is an error okay we are going to Roop use rule for each so pin LR out or as error single error right we Loop through each other and this one we in for each list here l i print out each other okay Eller okay save and then when we go back here we put orange three and this one 3.1 I think because I put only one decimal and this one save you see price Fields must have two decimals uh this is like doesn't match with my requirement so I need it to be decimal but sometime it is to be whole number so mean I will put 0 and this Max I will put two okay list me adjust this one and I will put 0 and Max I will put two let's save and Let me refresh this one let me put orange again and then let me put one and two point one description is uh Orange yellow okay save yeah it's work right now okay let's refresh this one see how about EB go back to the page and we put like the whole number you can put like mango mango yellow green mango okay save a product okay we have three products in database now so the next step we are going to print out all product in index page so let's take a look at the PowerPoint so to print the data out we have to make it through model we have to use model to get data from database and give it to controller and then controller will give this data to view and view will print it out for user okay let's go to our view which is index over here right we have no data and let's go to product controller so Index right so index controller doesn't connect with database or doesn't connect with model so it doesn't have data so to make is have data we have to call Mario over here so let me name variable products over here and then call model product okay we are going to get all products from the database so we can put all over here to get all products so we should get product before we return to view right then we will pass these products to view so how we can pass it we just put array at the end over here and then put array and then put products over here and then and then we pass this product to view okay now our view can get data from controller okay the next step we are going to print the data in a table let's create div over here and then let's create a table so I will put border one uh t r okay pH first one is ID and this one is name this mean copy this one to save time qty price description let's take a look at the table so refresh see we have table over here and then we can Loop data in table so we just put four each okay we can access product right variable this product is Form controller here from this one in products so this is how we access this through a view so if we Loop through it and then we put as product okay we look through each product and then we put in for each over here and we put TR [Music] and this one TD and then print our product ID okay copy this one this one should be name qty and this one price and the last one is description description okay save let's go back here and refresh see we see our data from database the next feature that we are going to do is to edit a product I'm going to put edit link after description over here okay if you see see in the PowerPoint so I'm going to start from Route okay and then controller model and view okay all right let me create link for edit over here I will put I will copy this one and change this one to edit okay this is where we put at the link so we Loop through each IVM and we put edit link so let me create a route first because when we need a link we need to create a route okay let's copy this one this one is get because it's only edit page and over here I can put parameter from products right we will get like product one product id2 so over here I just put a product and then over here we will pass this product to Route okay and then just put edit and over here I will use edit okay we have this one let's create uh this edit function in controller go to controller and then public function add it okay because we pass this edit right to this controller so over here we have to put product okay this product is this product and because this product is model okay so we put model in front of it and this one is variable product let's go back to round over here this one I'm going to change the name to product edit okay then go to index right now we can create a link by using a route that we just created okay I create a tag and then I put edit over here and I put a draft we call route over here and then we just put this name we call this name okay route this name and we have to pass array and then what we have to pass is product okay name is product this product is this product okay and then this is array we pass a product that's been looped through we pass this product to this route to send it to a controller and if we go back in we refreshed BBC added link over here if you inspect and we inspect the link you will see this is go to localhost products and ide3 which is this ID3 and then slash edit so if we click on the edit button or edit link I want it to show the data of products okay let's test if it can receive product over here so I'm going to dump product over here debug product okay and then if I refreshing again and then I click here see I see the product information over here we can use this information or we can use this product to edit the product okay so the edit page is quite similar to create so I'm going to copy the create page to save time just copy it Ctrl C and Ctrl V and then rename this one to edit.blade.php over here I change this one to edit a product okay we have view for edit okay we have this View we go back to product controller okay we return View so product edit so we return this product and then return product yeah so this is only edit page okay we receive this product return is to this view so for this view I'll go to edit right we can receive product so we can show the product over here we put value then we print our product name and I can copy this one and paste over here is one qty and this one is price and this one description okay for this one I will leave action to be empty for now we will create a link for update data later okay let's take a look over here refresh this page it's a view edit not file oh I forgot s over here they should have asked okay let's refresh this one again see it's become Apple 2 and this one is the old value that we want to update for example if we click on Orange it's going to show Orange quantity one over here and this button I'm going to change is to update okay let's see let's just change this one to update all right we get this page if we change this one to two and we click on update button I want the data to be updated in the database so first of all we are going to create a route to handle this data that's passed from juicer okay we create a route over here let's copy this one so when you update data you have to use method put okay and when you use this put in the form action you have to use put as well change this one to put okay and go back to here and you just change this one to update okay and over here we call update function we haven't created function in product controller yes we are going to product controller to create a public function update over here and then we receive products because we put products over here so we receive this over here and then we want to get information from the form so we use request and didn't request variable okay in update we are going to validate data as well so we can use this uh validation we just copy this one and paste it over here this data is the data that we received from the form okay we are going to pass this into product model so we are going to call this product over here called the product variable so we can update it so we put products and then we call update method and then we pass the data from the form over here and then when it's finished update we just return redirect we want this to redirect to the index page so we put route and then we call product index I forget s over here and I can send a message with it with success and then and then I can put product updated successfully okay I save it okay let's try to update this data okay for example I change orange to two and I click on update what's wrong put method no it's not support for the route I think I forget to put something over here or I forget to put another link Action Link over here okay let's put brow over here and then we call update Route we call this route so I change this one to update and then I copy this one and I put it over here all right and then I passed uh the product okay save and let's go back here let's go back here and let's go back here let's go back to index okay let's edit this one change this one to three and update we say product row is not defined over here there is no s over here here this route there's no s okay actually the data has been updated for example if you go back here you will see Orange has three if you edit this mango you change this to four you updated see it's redirect to here I just want to show the message over here if the product updates successfully okay let's go back here and then go to index and over here we are going to detect session success okay because we passed success with this uh request okay maybe here we are in here and then we put uh if session has success okay and add in if over here so we create another div here and we can print our success message over here session and then success so this success is this success okay which include this message product update successfully okay let's test it again refresh this one and add it over here changes one to five and update see product updated successfully so the UI is not look good because we focus on how laravel work so if you want to put CSS or you want to use like Tailwind framework you can do is by yourself okay the next step we are going to do we are going to create a delete link or a delayed button to delete this uh item or products from our application okay let's go to index over here and over here I copy this one and put this over here and we put delete over here and we create new table row and then over here I create form in order to delete data you have to use form okay and then input type submit value and delete okay so if you refresh over here you have delete button over here and form a method you have to use post and then action we are going to define the link later because we haven't created a loud yes and over here we have to put csrf for security purpose okay and then over here method we use delete here is the method that's the route used so if we go back to web over here we are going to create a route for the read we can just copy this one and put it over here so the method is delete and this one we can change to destroy or you can use delete but I like to use destroy and here we can call it destroy and here is destroy as well so we are going to create this function in product controller so we go to product controller go here and then we put public function destroy in Destroy we receive product from the route so we put product and then product variable see we receive this product and we put product over here so to delete product it's so easy call this product over here and then we call delete method okay and when the product deletes successfully we want to return redirect to the index page so we can copy this one and put it over here and then put this product deleted successfully as the success message okay what's out we have the route right now so we are going to use this loud to create link okay I want you to remember here in laravel we don't create a link directly in action instead we use a route name to generate a link for US Route and then you call product destroy and then what product do you want to destroy you have to pass the product inside here product that we look through all right this should be good so if you go back here you'll refresh the page and you click delete here and see the product deleted successfully if you delete it it's deleted successfully over here you can create a link to redirect to a create product page okay go here and this is index for example over here I can create a div and I can create a link so I put a tag then I put H graph and then I call route and then I call product dot create this is a round name of a product create page save it and over here we put create a product so EB refresh here if you click here it's redirect to this page we can create a new product banana quality three to three two two two uh description yellow one save see we get banana over here we can delete it or we can edit it all right this is all about this video If you like this video don't forget to click like subscribe and comment down below
Info
Channel: Devtamin
Views: 128,487
Rating: undefined out of 5
Keywords: programming, code, coding, coding tutorial, programming tutorial, web development, Laravel, Laravel CRUD, CRUD in Laravel, Laravel CRUD for Beginners, Laravel for Beginners, CRUD operation in Laravel, Learn Laravel, Build CURD in Laravel, Create CRUD in Laravel, Laravel tutorial, Laravel tutorial for beginner, tutorial Laravel, create read update delete Laravel, Laravel CRUD for beginners, Laravel CRUD from Scratch, Laravel 10 from Scratch, Easy Laravel CRUD, Easy Laravel
Id: _LA9QsgJ0bw
Channel Id: undefined
Length: 49min 58sec (2998 seconds)
Published: Fri May 12 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.