B
B
BonBon Slick2016-10-24 22:30:47
Laravel
BonBon Slick, 2016-10-24 22:30:47

Which is better to use for Route::get, or is it more common to pass data to a controller in Laravel?

I'm here in my thoughts, what should I use more often?
To submit a registration form with data and at login, etc. without options, only the form and the POST method , but such links as moving to pages, output, deletion, etc. whether it is worth collecting such data with a POST request and processing it. For example, such a situation, I have a lot of fields in the table, they are deleted by clicking on the button, a link is formed, where jQuery collects all the fields selected by the checkboxes, data, creating a dynamic link. To do this, you need to use this form of input to get the ID of the fields to be deleted:

<input type="checkbox" class="checkbox" name="check_row[]" value="{{$user->id}}">

Or, you should use a form where an array will already be accepted, something like this:
<input type="checkbox" class="checkbox" name="check_row[{{$user->id}}]"  >

Where we will directly pass the array form to the desired controller.
What do you suggest, advise? What, when, how and why is better?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WebDev, 2016-10-24
@BonBonSlick

Unclear question. In the first case, you are passing $user->id as the value for the check_row[ field; in the second, you are not passing any value for the check_row[$user->id] field.
If this is, for example, a list of users and you mark with checkboxes who to delete, then it is more logical to use the first option.
The second option is applicable if, for example, you have a list of users and you need to set different values ​​for all, for example:

check_row[1][is_manager]
check_row[1][salary]
...
check_row[2][is_manager]
check_row[2][salary]
...

This is used on pages where a large form and each row is a user, and each user has a bunch of fields. And at the bottom there is one "Update" button.
In general, the first option is more convenient and easier, if you can get by with it, use it.

V
Vyacheslav Plisko, 2016-10-25
@AmdY

The rule is very simple - displaying data - GET, changing data - ONLY POST.
Moving through pages is a display, so GET is needed, at the same time it allows you to save the state in the link.
Deleting data is a change, so it's a POST, and we don't have a stateful link that accidentally deletes everything by going to. Google somehow experimented with preloading pages when reading emails and cleaned up a couple of stores that sent letters tied to GET for admins.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question