Feralheart
Feralheart

Reputation: 1920

Laravel: Automatic populate from database

First Laravel Project. I want to populate a table automiticaly from database

The table looks like this:

{{ Form::open(array('url' => '/invoicenew/$invoicenum')) }}
<table border=1 align=center>
    <t>
        <td colspan=3>
            <table>
                <tr>
                    <td>ACME INC.</td>
                </tr>
                <tr>
                    <td>Post code, City</td>
                </tr>
                <tr>
                    <td>Address</td>
                </tr>
                <tr>
                    <td>Tax number</td>
                </tr>
            </table>
        </td>
        <td colspan=3>
               <table>
                <tr>
                    <td>{{ $supplier[0]->name }}</td>
                </tr>
                <tr>
                    <td>{{ $supplier[0]->postcode}} {{ $supplier[0]->city}}</td>
                </tr>
                <tr>
                    <td>{{ $supplier[0]->address }}</td>
                </tr>
                <tr>
                    <td>{{ $supplier[0]->taxnumber }}</td>
                </tr>
            </table>
    </tr>
    <tr>
        <td colspan=2>Invoice number:</td><td>{{ $invoicenum }}</td>
        <td colspan=2>Invoice date:</td><td>{{ $invoicedate }}</td>
    </tr>
    <tr>
        <td>Barcode</td><td>Name</td><td>Count</td><td>Netto Price</td><td>Brutto Price</td><td>VAT kex</td>
    </tr>
    <tr>
        <td>{{Form::text('barcode')}}</td><td></td>{{Form::text('count')<td></td><td></td><td></td><td></td>
    </tr>
    <tr colspan=6>{{Form::submit('Next>>')}}</tr>
</table>

I want to fill the Name, Netto Price, Brutto Price and VAT key from table inventory instantly after I write the barcode in the field.

How can I accomplish it?

Upvotes: 1

Views: 1037

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163758

Use the form model binding feature.

Often, you will want to populate a form based on the contents of a model. To do so, use the Form::model method:

{!! Form::model($user, ['route' => ['user.update', $user->id]]) !!}

Now, when you generate a form element, like a text input, the model's value matching the field's name will automatically be set as the field value. So, for example, for a text input named email, the user model's email attribute would be set as the value. However, there's more! If there is an item in the Session flash data matching the input name, that will take precedence over the model's value.

Upvotes: 2

Related Questions