Using automatic validation in models
When validating data that's being sent to the database, ideally we should put the rules and validation in our model. In this recipe we'll see one way to accomplish this.
Getting ready
For this recipe, we need a standard Laravel installation with a configured MySQL database. We also need our migrations table set up by running the Artisan command php artisan migrate:install
.
How to do it...
To complete this recipe, follow these steps:
In the command prompt, create a migration for a simple
users
table:php artisan migrate:make create_users_table
Create the schema in the migration file. The file is located in the
app/database/migrations
directory and will be named something like2012_01_01_222551_create_users_table.php
:use Illuminate\Database\Migrations\Migration; class CreateUsersTable extends Migration { /** * Make changes to the database. * * @return void */ public function up() { Schema::create('users', function($table...