Birmingham mumbai


Download 1.3 Mb.
Pdf ko'rish
bet53/68
Sana05.01.2022
Hajmi1.3 Mb.
#227543
1   ...   49   50   51   52   53   54   55   56   ...   68
Bog'liq
Laravel 5 Essentials

Method

Route

Description

GET


/

Index


GET

/cats


Overview page

GET


/cats/breeds/:name

Overview page for specific breed

GET

/cats/:id



Individual cat page

GET


/cats/create

Form to create a new cat page

POST

/cats


Handle creation of new cat page


Chapter 3

[

 25 

]

Method

Route

Description

GET


/cats/:id/edit

Form to edit existing cat page

PUT

/cats/:id



Handle updates to cat page

GET


/cats/:id/delete

Form to confirm deletion of page

DELETE

/cats/:id



Handle deletion of cat page

You will shortly learn how Laravel helps us to turn this routing sketch into actual 

code. If you have written PHP applications without a framework, you can briefly 

reflect on how you would have implemented such a routing structure. To add 

some perspective, this is what the second to last URL could have looked like with 

a traditional PHP script (without URL rewriting): 

/index.php?p=cats&id=1&_

action=delete&confirm=true

.

The preceding table can be prepared using a pen and paper, in a spreadsheet 



editor, or even in your favorite code editor, using ASCII characters. In the initial 

development phases, this table of routes is an important prototyping tool that makes 

you to think about URLs first and helps you define and refine the structure of your 

application iteratively.

If you have worked with REST APIs, this kind of routing structure will look familiar 

to you. In RESTful terms, we have a 

cats

 resource that responds to the different 



HTTP verbs and provides an additional set of routes to display the necessary forms.

If, on the other hand, you have not worked with RESTful sites, the use of the 

PUT

 

and 



DELETE

 HTTP methods might be new to you. Even though web browsers do not 

support these methods for standard HTTP requests, Laravel uses a technique that 

other frameworks such as Rails use, and emulates those methods by adding a 

_method

 

input field to the forms. This way, they can be sent over a standard 



POST

 request and 

are then delegated to the correct route or controller method in the application.

Note also that none of the form submissions endpoints are handled with a 

GET

 

method. This is primarily because they have side effects; a user can trigger the 



same action multiple times accidentally when using the browser history. Therefore, 

when they are called, these routes never display anything to the users. Instead, they 

redirect them after completing the action (for instance, 

DELETE /cats/:id

 will 

redirect the user to 



GET /cats

).


Download 1.3 Mb.

Do'stlaringiz bilan baham:
1   ...   49   50   51   52   53   54   55   56   ...   68




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling