Laravel 5从视图/商店请求表上的行

I'm working on developing a system of applications with Laravel 5.2. I have some <select>s to select the products and report the amount. It will generate a table with a list of products selected for the application. How do I retrieve this information table in my controller?

[updating] Excuse me English, but my question is as shown in the image, by clicking the button of "submit order" I can read the <table> <tr> <td> with added products and save the products in Order_Details table.

enter image description here

Actually, for a select you'll need two fields: the value (in the most of cases the Id) and another element to display as key. Eloquent provides an useful method called "lists": it returns a collection of key/value elements.

$model = Model::lists('key', 'value');

Replace your 'key' and 'value' fields with your column's name. The next step is using the retrieved data in your view. You've got two different ways to solve this part of the problem:

  1. Manually iterate through the collection to compose your select statement
  2. Use the LaravelCollective Html helper

The La ravelCollective HTML helper has a lot of methods that I'm sure you'll find useful in your coding. It even includes a method for creating dropdowns.

In order to retrieve the information that is on that table in a controller, you need to POST the data.

First you'll need a post route in your App\Httpoutes.php file:

Route::post('pedidos', [
    'as' => 'post-pedidos',
    'uses' => 'PedidosController@post'
]);

Now you can create a form which will gather all the data that will be sent to that route. It should contain the table which your products dropdown input will generate:

<form method="post" action="{{ route('post-pedidos') }}">

    {{ csrf_field() }}
    <table>
        // Put table rows + input here
    </table>
</form>

Now, all you need to do is make sure your rows have actual inputs on them, which will be submitted with the form. Something like this?

<input type="hidden" name="codigo[0]" value="30628">
<input type="hidden" name="quantidade[0]" value="90">

To see what you'll need on PedidosController's post method, check out how to retrieve data from a request and how to validate it before inserting it into the database.