I have my DB, already migrated everything, my code can record new entries in my table when required, and so on.
I have a table with the contents of: 'id', 'name', 'lastname', 'email', 'phone', 'address'.
What I want is, when you hit the submit button, you'll be redirected to a new 'view.blade.php' where you can see all of the DB's entries, including the most recent. BUT I don't know how to develop this code to make it work.
I need help with that, please. Thank you.
In your controller function do this right after you store a new record to table.
assuming your model name is User
fetch all user records from User model,
$users = App\User::all();
pass this users variable to view(assuming your view.blade.php
is in resources/views
folder)
return View::make('view', compact('users'));
and then in your view.blade.php you can do something like this to display all user records.
<table>
<thead>
<tr>
<th> id</th>
<th> name</th>
<th> last name </th>
<th> email </th>
<th> phone</th>
<th> adddress </th>
</tr>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td> {{$user->id}} </td>
<td> {{$user->name}} </td>
<td> {{$user->last_name}} </td>
<td> {{$user->email}} </td>
<td> {{$user->phone}} </td>
<td> {{$user->address}} </td>
</tr>
@endforeach
</tbody>
</table>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With