I'm trying to get data from database to my view page using Laravel 8.
the table's name is "users" [id, name, email, etc...] it's autogenerated from Jetstream, connection and login register works fine !
I only want to view table users list (id and names).
Here is my editprofile.blade.php file :
<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>
and here is my routes/web.php file (the blade is under a folder called profile so the path is profile/editprofile.blade.php)
Route::get('profile/editprofile', function () {
$petani = DB::table('users')->get();
return view('profile/editprofile', ['petani' => $petani]);
});
Please how Can I show data in my page ?
Why don't just use Eloquent models as it's shown in the offical documentation. So to query all users you would do something like this:
Route::get('profile/editprofile', function () {
$usres = \App\User::all();
return view('profile/editprofile', ['petani' => $usres]);
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments