【发布时间】:2021-05-11 12:18:45
【问题描述】:
我正在尝试使用 Laravel 8 将数据从数据库获取到我的视图页面。
表的名字是"users" [id, name, email, etc...]它是从Jetstream自动生成的,连接和登录注册工作正常! p>
我只想查看表用户列表(id和名称)。
这是我的 editprofile.blade.php 文件:
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __('Edit Profile') }}
</h2>
</x-slot>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
<h1>This is a private page </h1>
@foreach($petani as $key => $data)
<tr>
<th>{{$data->id}}</th>
<th>{{$data->name}}</th>
</tr>
@endforeach
</div>
</div>
</div>
这是我的 routes/web.php 文件 (刀片位于名为 profile 的文件夹下,因此路径为 profile/editprofile.blade.php)
Route::get('profile/editprofile', function () {
$petani = DB::table('users')->get();
return view('profile/editprofile', ['petani' => $petani]);
});
请问如何在我的页面中显示数据?
【问题讨论】: