- Hands-On Full Stack Web Development with Angular 6 and Laravel 5
- Fernando Monteiro
- 355字
- 2021-07-23 19:18:46
Creating routes
The routes within Laravel are responsible for directing all HTTP traffic coming from the user's requests, so the routes are responsible for the entire inflow in a Laravel application, as we saw in the preceding diagrams.
In this section, we will briefly look at the types of routes available in Laravel, and how to create a simple route for our MVC component.
At this point, it is only necessary to look at how the routes work. Later in the book, we will get deeper into application routing.
So, let's look at what we can use to handle routes in Laravel:
Code HTTP | METHOD |Verb
Route::get($uri, $callback); GET
Route::post($uri, $callback); POST
Route::put($uri, $callback); PUT
Route::patch($uri, $callback); PATCH
Route::delete($uri, $callback); DELETE
Route::options($uri, $callback);
OPTIONS
Each of the routes available is responsible for handling one type of HTTP request method. Also, we can combine more than one method in the same route, as in the following code. Do not be too concerned with this now; we'll see how to deal with this type of routing later in the book:
Route::match(['get', 'post'], '/', function () { // });
Now, let's create our first route:
- On your text editor, open web.php inside the routes folder, and add the following code, right after the welcome view:
Route::get('/band', function () {
return view('band');
});
- Open your browser to http://localhost:8081/band, and you will see the following message:
Hi i'm a view
Bravo! We have created our first route. It is a simple example, but we have all of the things in place and working well. In the next section, we'll look at how to integrate a model with a controller and render the view.
- 物聯網工程規劃技術
- 物聯網智慧安監技術
- HTML5 Game development with ImpactJS
- 通信簡史:從信鴿到6G+
- 數字通信同步技術的MATLAB與FPGA實現:Altera/Verilog版(第2版)
- Wireshark網絡分析就這么簡單
- Yii Application Development Cookbook(Second Edition)
- 物聯網長距離無線通信技術應用與開發
- CCNP TSHOOT(642-832)認證考試指南
- Learning Windows 8 Game Development
- Learning Node.js Development
- 云工廠:開啟中國制造云時代
- 全聯網標識服務
- 基于IPv6的家居物聯網開發與應用技術
- 5G非正交多址接入技術:理論、算法與實現