How to get data from database to view page in laravel?(如何从数据库中获取数据以在 laravel 中查看页面?)
问题描述
我正在使用 Laravel 5.4,我想从我的视图页面 (listpetani.blade.php) 中查看数据库中的数据.
I am using Laravel 5.4 and I want to view my data in database from my view page (listpetani.blade.php).
这是我项目的代码:
HTML:
<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>
PHP:在我的 listpetani.blade.php 我有一个空表,我想显示来自 数据库tbl_user:
PHP:
In my listpetani.blade.php I have an empty table and I want to show data from 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]);
});
我页面中的表格:在浏览器中查看
我想在 laravel 5.4 中将数据库中的所有数据显示到我的视图中.有人可以帮帮我吗?
I want to show all the data from database into my view in laravel 5.4. Can anybody help me?
推荐答案
[SOLVE]
谢谢大家,这个问题我已经解决了
Thank you guys, I already solve this problem
这是解决的代码
web.php(路由)
web.php (routes)
Route::get('listpetani', function () {
$petani = DB::table('tbl_user')->get();
return view('listpetani', ['petani' => $petani]);
});
在我的 listpetani.blade.php
@foreach($petani as $key => $data)
<tr>
<th>{{$data->id_user}}</th>
<th>{{$data->nama_user}}</th>
<th>{{$data->alamat}}</th>
<th>{{$data->no_telp}}</th>
<th>{{$data->id_lokasi}}</th>
</tr>
@endforeach
这篇关于如何从数据库中获取数据以在 laravel 中查看页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何从数据库中获取数据以在 laravel 中查看页面?
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 如何替换eregi() 2022-01-01
