No ratings yet.

 

 

 

 

what is routing in laravel

Basic Routing
Let’s take a look at a request being made to the Laravel framework.
1 http://domain.com/my/webpage
In this example, you are using the http protocol to access your Laravel
application hosted on domain.com. The my/webpage portion of the URL is what we will use to route web
requests to the appropriate logic.
I’ll go ahead and throw you in at the deep end.
Routes are defined in the app/routes.php file, so let’s go ahead and create a route that will listen for the request we mentioned above.
1 <?php
2
3 // app/routes.php
4
5 Route::get(‘my/webpage’, function() {
6 return ‘My First Rout!’;
7 });
Now type
http://domain.com/my/webpage into your web browser.
If everything has been configured rightly, you will now see yourself the words ‘My First Rout!’.
We can declare routs by using rout class.
First point keep it in your mind.
:: The get part is a method on the route class that is used to ‘catch’ requests that are made using the HTTP
verb ‘GET’ to a certain URL.
All requests made by a web browser contain a verb. Most of the time, the verb will be GET,
which is used to request a web page. A GET request gets sent every time you type a new web address
into your web browser.
1 <?php
2
3 // app/routes.php
4
5 Route::get();
6 Route::post();
7 Route::put();
8 Route::any();
All of these methods accept the same parameters, We will go into more detail on this topic
later. For now, all you need to know is that GET is used to make requests, and that POST is used when
you need to send additional data with the request.

what is Route::any()

The Route::any() method is used to match any HTTP verb. However, I would recommend using
the correct verb for the situation you are using it in to make the application more transparent.

1 <?php
2
3 // app/routes.php
4
5 Route::get(‘my/webpage’, function() {
6 return ‘My First Route!’;
7 });

Now we craating rout logicin app/routes.php
1 <?php
2
3 // app/routes.php
4
5 $logic = function() {
6 return ‘My First Route!’;
7 }
8
9 Route::get(‘my/webpage’, $logic);
what we are doing above we are passing webpage route with $logic function.
In this instamatches the URI my/page. Under these conditions, the return statement will be
processed and the “Hello world!” string will be handed to the browser.
You can define as many routes as you like, for example:
1 <?php
2
3 // app/routes.php
4
5 Route::get(‘first/webpage’, function() {
6 return ‘i got it first!’;
7 });
8
9 Route::get(‘second/webpage’, function() {
10 return ‘i got it second!’;
11 });

Now check your self what is there with your coding with routes.
open broswer and type there in address bar
1 http://domain.com/first/webpage
2 http://domain.com/second/webpage
If you are on localhost type in address bar:
localhost/laravel/first/webpage
localhost/laravel/second/webpage

what is routing in laravel

for more resources , click here

Please rate this