1

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?

1 Answer 1

2

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.

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

3 Comments

Thank you, I will give it a try. And it populates automaticly, without the need of using a submitbutton?
@Feralheart it will populate the data from the DB or session to the form. If you want to insert form data to the DB, just use Mode::create($request->all())
Tried it, but I got error: ErrorException in fc866e34e8db63b9c28089b5deb0ed88644f0a4e.php line 4: Undefined variable: inventory (View: /var/www/html/project/laravel/leltar/resources/views/invoicesecond.blade.php) How I tried: {!! Form::model($inventory, array('url' => '/invoicenew/$invoicenum', $inventory->barcode)) !!}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.