Creating a CRUD system
To interact with our database, we might need to create a CRUD (create, read, update, and delete) system. That way, we add and alter our data without needing a separate database client. This recipe will be using a RESTful controller for our CRUD system.
Getting ready
For this recipe, we'll be building on the User tables created in the recipe Using automatic validation in models.
How to do it...
To complete this recipe, follow these steps:
In the
app/controllers
directory, create a file named asUsersController.php
and add the following code:<?php class UsersController extends BaseController { public function getIndex() { $users = User::all(); return View::make('users.index')->with('users',$users); } public function getCreate() { return View::make('users.create'); } public function postCreate() { $user = new User(); $user->username = Input::get('username'); $user->email = Input...