Thursday, August 20, 2015

Basic Routing in Laravel 5.1

I'm using laravel version 5.1.10 in this post. If you still don't install it, you can see about my laravel installation process here and here. Aaand...I'm using XAMPP for viewing the laravel default page.
Okieee... Routing.... I don't really know about the best definition for routing :D But I just can say that Routing is something that can handle our request when we are typing a web page on the browser hehehe....For example when we are typing "www.google.com", this routing will capture that url then give us the available web page that can be accessed on the google server. Let's see an example in Laravel 5.1. Go to app/https then open the routes.php as shown below :
Default routes code is shown below :
Well.. What does this code do...? the answer is shown in below picture :
Sooo... the "/" in get function is like a directory that we requested on the web browser and return value of this get function is the content of page that is shown in our browser. Okiee... Let's change the return value :
This code will result :
Next, let's change the slash sign of get function as follow :
Now when opening the page, we have to add ~/hyosoka at the end of the url page because I'm changing the '/' to 'hyosoka' so the url now is http://localhost/HisokaLaravel/public/hyosoka 
I hope above examples give you a good sense about how this route works on laravel hehehe...:D
Next, let's add some parameters to get function as shown below :
The result is :
Ummm... What happen if we open the page without itachi at the end...??? Let's see...
So we need to add a simple handler if user doesn't put itachi at the end of url page. It's just a simple code like :
The result if itachi == null or user didn't put the itachi at the end of url page :
Soo... That's the basic routing in laravel according to Hyosoka's mind :D.... Thanks... :-)

No comments:

Post a Comment