standard routing
The adhering to picture shows the process accomplished when we enter a LINK. It likewise reveals the design of the MVC pattern that Laravel makes use of for job advancement.
When we get in an URL directly from the web browser, we do it with a GET kind of HTTP request. This request is sent to the routes.php file located inside app/Http/routes. If it does not exist, PHP will provide us with an error. If the path exists, it will take us to a controller in which the reasoning is located; the controller will engage with a design (additionally) to recover information from a database. These details go to the controller, and from the controller, we invoke a sight. The views are located in the resources/views directory. Lastly, the company is packed and shown in the internet browser.
This is how the MVC (Model-View-Controller) version works.
Mean we want to enter the adhering to URL HTTP:/ domain.com/greeting and display a page with the message "Welcome:-RRB-." In Laravel, the/ welcoming section would come from a route that returns an action or a sight depending upon just how complicated what we intend to present comes to be. The domain.com part will come from localhost if we are examining it locally. In our example, we will certainly reveal an extremely straightforward message, so it is not necessary to show a sight. To achieve this, we will certainly do the following:
Route:: get(' saludo', function () );.
Which should display a message similar to this.
Route kinds per HTTP header.
Paths are constantly declared making use of the Route course. That's what we contend the start, before the::. The obtain component is the method we use to 'catch' requests that are used the HTTP 'GET' verb to a details link.
As you will see, all demands made by a web internet browser consist of a verb. It will obtain the verb the majority of the moment, which is utilized to ask for a website. Every time you type a new internet address in your internet browser, a get request is sent out.
Although it is not the only demand, there is also a blog post that is utilized to make a demand and use some data. Usually used to submit a type where information needs to be raised without displaying it in the URL.
There are various other HTTP verbs available. Below are several techniques that the directing class has offered to you.
Route:: get();.
Route:: post();.
Route:: any();.
Route:: delete();.
Route:: put();.
Any technique of the Course course constantly receives two debates. The initial is the URI with which we intend to match the URL, and the 2nd is the function to do, which in this situation is a Closure that is absolutely nothing greater than a confidential function, it is Say, it does not have a name.
Obtain routes.
In this case, we will certainly use the fixed get method to compose a path that responds to a demand of this type. The obtain type routes are one of the most used. The limited get method gets as a first criterion a string showing the link with which we are going to get in, the string "/ alumnus" will certainly respond to the demand http://localhost:8000/alumnos, the string "/" is equivalent to htpp:// localhost:8000, that is, the default route. As a second parameter, the fixed method obtains a closure( an unnamed feature) that can return a view or a string.
// ruta de tipo GET que devuelve una vista.
Route:: get('/', function () );.
// ruta de tipo GET que devuelve un simple string.
Route:: get('/', function () );.
The sight technique inside the closure gets the name of a view as a criterion without the expansion. In the instance above, the sight welcomes are located in resources/views/welcome. blade.php if we create sight(' pasteles. lista _ pasteles'), we show that it will return the data lista_cakes. blade.php situated in resources/views/cakes/ lista_cakes. blade.php. We will certainly see the views in chapter 10.
It can connect routes to the techniques of a controller. The course http://localhost:8000/home will return whatever we define in the Controller HomeController's index method in the following example.
Course:: get(' residence', 'HomeController@index');.
Criteria in the paths of a kind get.
It can use path parameters to introduce extra padding worths into your course definitions. This will create a pattern on which we can collect sections of the URI and pass them to the application reasoning handler. We will certainly offer some examples to make it a little clearer.
In the previous photo, we can see two brand-new ideas, the use of default values which we accomplish with the icon (?) after the variable's name, and in the feature appointing a default value, in this situation, the integer 1.
The 2nd point we see is the use of the method, which allows us to establish regular expressions to the variables that we use in creating the URIs.
php interview questions
Comments
Post a Comment