Laravel is an PHP framework. It’s one of the most popular framework among a lot of PHP frameworks. Route is the first thing you will come across when you will start learning Laravel. Here I will try to cover some basis of Route like: Route’s structure, Multiple Route, Passing Parameter(s) and Naming Route.
Route is a class in Laravel where you have “get”, “post”, “put”, “patch” and “delete” static methods. You need to pass 2 parameters into the method. The first parameter you provide is the path/route of your file which you want to load. If you type that path into the URL of your browser you will see the page you intended to see. The second parameter could be anything. In the below picture it’s a closure (call back function). The job of this closure is to do something when you access the URL. In the below picture the closure is returning a welcome page. This is the first page you see when you first install Laravel.
www.beebitbyte.com. When you pass the URL as 1st parameter Laravel adds the root path so you do not have to add it explicitly. You just need to provide what comes after domain name as domain name is common for every route.
It’s simple. Just add another route with same 2 numbers of parameter. Change the path to locate your file in view. In the below picture I am just returning a string “This is about page”. And if you type
“http://laravel.app/about”you will see “This is about page” in your browser.
“http://laravel.app/”. For you it should or could be different.
A lot of time you need to pass parameter(s) through your URL. For example if you have bunch of items in your database and you would like to show the 1st item then you need to pass the id of that item. In the below example we will be passing the id for items.
“http://laravel.app/item/1”in your browser URL you will see this result: “The id passed through URL is 1”
If you find the path is too long in a route you can give it a short name. This is useful to put an a long URL in an anchor tag.
href=“route(‘item.list’)”. If you access this URL “/item/show/list” now you will see the whole URL. For me it looks like this:
php artisan route:list