Wednesday, March 29, 2017

How to get data from database to view page in laravel?

i used Laravel 5.4 and i want to view my data in database from my view page in laravel (listpetani.blade.php) here the code of my project.

<div class="table-responsive">
                            <table class="table table-striped table-hover table-condensed">
                                <thead>
                                    <tr>
                                        <th><strong>No</strong></th>
                                        <th><strong>Nama Petani</strong></th>
                                        <th><strong>Alamat</strong></th>
                                        <th><strong>No. Handphone</strong></th>
                                        <th><strong>Lokasi</strong></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                        <th></th>
                                    </tr>
                                </tbody>
                            </table>
                        </div>

in my listpetani.blade.php i have table (empty) and i want to show data from database database tbl_user

Route::get('listpetani', function () {

$petani = DB::table('tbl_user')->pluck('id_user', 'username', 'alamat', 'no_telp', 'id_lokasi');

return view('listpetani', ['petani' => $petani]);

});

and the table in my page: view in browser

i want to show all the data from database into my view in laravel 5.4. anybody can help me? thanks before.



via Yosua Simanjuntak

Advertisement