0

I never understand these 2 completely, can someone please put an end to this ?

I have 2 routes :

1- Route::get('/admin/dashboard', 'DashboardController@dashboard');

2- Route::post('/admin/dashboard', 'DashboardController@dashboard_post');


If I do this

{hostname}/admin/dashboard?test=123

My first route should trigger.

If I create a form, with 1 input and submit the form to /admin/dashboard

My second route should trigger.


What is different between these 2 POST ?

Are they behaving the same thing ?

How would one know to use one over the other ?

0

2 Answers 2

1

You have to specify in your form whether it's submitting a GET or a POST request.

<form action="/action_page.php" method="get"> will send a GET request and trigger the first route.

<form action="/action_page.php" method="post"> will send a POST request and trigger the second one.

More about the difference between get and post.

Sign up to request clarification or add additional context in comments.

Comments

1

Its basically a matter of what they are used for. If you want to e.g. create something new or upload a file you should use a POST request. If you want to get Information from the Server, which is already there (e.g. data from a database) you should use GET.

To sum it up in short: Use POST for sending data and GET to receive data from the server.

For your form: you have to specify which request method should be used:

<html> // Use GET <form action="form.php" method="GET"> <input type="text" name="text"> <button type="submit">Submit</button> </form> // Use POST <form action="form.php" method="POST"> <input type="text" name="text"> <button type="submit">Submit</button> </form> </html> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.