Hello friends, Tony here, welcome. Now here I have opened the Laravel project. And let's see where this page is coming from.
Okay, I'm going to open the routes. And inside the route, we have this web.php here we defined all the routes. And here we have only one route, we have this route facade, and calling the get method, which means when we make a get request to this URL, so slash URL, por slash, we are going to execute.
this function. And this function is going to return a view welcome, which means it's going to return a view which is inside the resources views. And here we have the name of the page. So here we have the welcome.blade.php. Here we have the welcome.
As you can see, we don't specify the.blade.php, just the name of the view. And that's return this view. So if I change it. something inside this welcome.blade.php. So let's say I'm going to select all and just add an HTML, let's say HTML5, and here I'm going to add a H1 saying hello world.
If I come here and refresh now, we have hello world here, as you can see. Okay, let's open the web routes and Here we can return also a string if you want. So let's say just, or let's create a new route. So let's create a new route here. The same thing, route get.
So when you make a get request, now here we have the slash. Here I'm going to say just test. When you make a get request slash test, I'm going to say just return a string test.
and let's save let's open the project refresh and let's visit now the slash test hit enter and now as you can see we have a test here but just let me add this one in the h1 not hello world but just test saying here and now refresh we have a test that's one okay you also can return can create a variable here. So let's say dollar sign test variable or something else, passing the test and then we can concatenate that and displaying the variable. So dollar sign test here.
If I save, come here and refresh, we have test if I changed test again, for example, and refresh now we have test again here okay now this is for the get request so when we visit the slash test with the guide request which is the default one let's see with another or with the copy of this one with a post request so the post request is typically when we uh submit a four so i'm going to make a post request the slash for slash here here we have get request and i'm going to create a one for post request what i want so let's say i'm going to use the request facade from laravel and don't worry we are going to learn we need to import that we are going to learn about this request and for now just i'm going to say uh die and dump the request all okay now on the welcome here when we make a visit we return that welcome i'm going to add a form here so let's say without the form with action to be slash and the method is going to be post then we need to add the csrf token which is for protection without an input and then not input but just say button type submit and say submit and also now we need to close the four okay so here we have an example for form with the action the b for slash the method is post we added this csrf token which is for protection and then an input with type text and name name so the name based on the name we are going to get the request here So for example, I'm going to say a username here. And let's save. So when we make a post request, we are going to just die and dump the request.
Oh, he will define the post route. Now let's come here and refresh. We need to visit the slash on page. And I'm going to zoom it a little bit.
And let's say just test for now. Hit submit. As you can see, we have a die and dump. We have an underscore token, which is...
This CSRF token, as I told you, which is for protection, and then we have a username key with this test value. If I go back and refresh and update this, so for example, test updated, make a submit request, now we have username to be a test updated, as you can see. Okay, this is for the post request, but also we have a put, patch, and delete requests. So let's see also then I'm going to make a put request and the same thing I'm going just to say dynadump request all.
Now let's go back to welcome and create another form. And here this is going to be a put request. Now, instead of saying here put request, because not all the browsers support this, what we can do is. After this one, we can say add an input with a type to be hidden and the name is going to be underscore method and the value put. Okay, so we're going to override the method and let's say submit put save from here and go back refresh.
Now we have this submit put, and I'm going to say just put request. If I say submit, as you can see, we have a token, the method, which is a put, and the username, which is a put request. So just to understand you, if I, instead of dying down the request old, I'm going to return, for example, a string put request here.
Save. Now let's go back and refresh. Just type something here and say submit put.
We had a return put request. Okay, let's go back and refresh. Now typically when we make a put request we also need the ID of that.
For example, if we want to update the post we need the ID of the post and we put that ID inside the calibrations here and we specify for example, ID or slug ons or something like this here on the function where I'm going to accept also the ID by saying dollar sign ID. And let's say I'm going to return that ID now. So just assign ID, let's save and let's go back where we have a bomb with action. And here when we say slash, we add the ID, for example, the ID 1. And if I save that, and let's refresh here and just say submit the put request, we have ID 1. If I go back and change that to 100, for example, let's say come here and refresh. Let's say submit.
Now we have 100. So we get the ID we put here. And in real world projects, this is going to be dynamic. But for now...
We're going to stick with this approach. Okay, now let's go here. And instead of saying input type hidden, something like this, in Laravel, we can just use the blade helper, which is a method.
And here we're specifying this is going to be a put request. Now if I save and just go back, refresh, submit the put request, we have the same result. Good.
Now let's create one more for the delete request copy here and paste down there and here we have to specify this is going to be a delete request and typically here we delete the record so what I'm going to do I'm going just to receive the ID and return the ID but in the reward we are going to delete the post on the ID, okay, and then return some return back, for example, but for now, I'm going to just return the ID just to see you. So return here, refresh. Let's go and make another form for delete.
We have 100 method post now specifying the change in that the delete and here we don't need the input. We just saying submit delete here. If I save and come here and refresh we have a submit delete.
If I. click submit delete we turn 100 so if we change that to 1000 come here and go back refresh submit delete we have 1000. okay friends that's it for the web routes so here we have defined a get request when we visit the slash for slash the home page then here we have a post request for for slash and we have put request for for slash also passing the id and the delete request passing also here the id and just return the id here okay friends that's it all about this video i hope you enjoy and if you like such a video don't forget to subscribe to my channel like the video share with your friends and see you in the next one all the best thank you very much