Laravel Tutorial 1: Intro to Routing 06-02-2022, 11:22 PM
#1
In the previous tutorial we installed Laravel and got it up and running. In this tutorial we will cover Routing in laravel. Don't forget to serve the application with php artisan serve when trying to visit the URL's.
What is Routing?
Routing is directing user requests to where they need to go. Laravel takes care of the Pretty URLs for us. Pretty URLs are a way to replace the querystring in the URL with something more eye pleasing. Instead of ?user=2f3rg&redir=1&something=else&here we would see something like /user/2ferg/redir/1/something/else/here.
Web Routes
The first thing we are going to do is edit the web routes file. It is located at routes/web.php
![[Image: Screenshot-2022-06-02-3-07-21-PM.png]](https://i.ibb.co/PMQnwjs/Screenshot-2022-06-02-3-07-21-PM.png)
The first route is the default route that is loaded by default. The next route was created by me. You can see the route the original code points to is called welcome. In the MVC architecture I know that there is probably a view named welcome. You can visit the URL http://localhost:8000/
Views
You can find your views folder in the resources folder. We can edit the welcome view by accessing it at resources/views/welcome.blade.php.
![[Image: Screenshot-2022-06-02-3-13-27-PM.png]](https://i.ibb.co/6vrW1GP/Screenshot-2022-06-02-3-13-27-PM.png)
I edited the links at the bottom of the page. I removed the links and made my own link that points to a view named user. Now we can copy the welcome.blade.php file into user.blade.php.
![[Image: Screenshot-2022-06-02-3-17-03-PM.png]](https://i.ibb.co/xLV4bJt/Screenshot-2022-06-02-3-17-03-PM.png)
And edit the user.blade.php file to say something like User dashboard. And if you visit the URL http://localhost:8000/user you will see this:
What is Routing?
Routing is directing user requests to where they need to go. Laravel takes care of the Pretty URLs for us. Pretty URLs are a way to replace the querystring in the URL with something more eye pleasing. Instead of ?user=2f3rg&redir=1&something=else&here we would see something like /user/2ferg/redir/1/something/else/here.
Web Routes
The first thing we are going to do is edit the web routes file. It is located at routes/web.php
![[Image: Screenshot-2022-06-02-3-07-21-PM.png]](https://i.ibb.co/PMQnwjs/Screenshot-2022-06-02-3-07-21-PM.png)
The first route is the default route that is loaded by default. The next route was created by me. You can see the route the original code points to is called welcome. In the MVC architecture I know that there is probably a view named welcome. You can visit the URL http://localhost:8000/
Views
You can find your views folder in the resources folder. We can edit the welcome view by accessing it at resources/views/welcome.blade.php.
![[Image: Screenshot-2022-06-02-3-13-27-PM.png]](https://i.ibb.co/6vrW1GP/Screenshot-2022-06-02-3-13-27-PM.png)
I edited the links at the bottom of the page. I removed the links and made my own link that points to a view named user. Now we can copy the welcome.blade.php file into user.blade.php.
![[Image: Screenshot-2022-06-02-3-17-03-PM.png]](https://i.ibb.co/xLV4bJt/Screenshot-2022-06-02-3-17-03-PM.png)
Code:
cp resources/views/welcome.blade.php resources/views/user.blade.php
And edit the user.blade.php file to say something like User dashboard. And if you visit the URL http://localhost:8000/user you will see this:
![[Image: Screenshot-2022-06-02-3-17-07-PM.png]](https://i.ibb.co/nspMrFg/Screenshot-2022-06-02-3-17-07-PM.png)
scarylerie.com