A GET request to /crud/all
will show all the users in the users
table.
Lets create the get_all()
method in Crud_Controller.php
.
public function get_index() { $all_users = DB::table("users")->get(); return View::make("all-users", ["all_users"=>$all_users])]); }
Create a file all-user.php
in app/views
directory
<table> <tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Gender</th> </tr> <?php if( empty($all_users) ) { ?> <tr> <td colspan="4">No users found</td> </tr> <?php } else { foreach($all_users as $user) { ?> <tr> <td><?php echo $user->id; ?></td> <td><?php echo $user->first_name; ?></td> <td><?php echo $user->last_name; ?></td> <td><?php echo $user->gender; ?></td> </tr> <?php } } ?> </table>