[Laravel] form validation

1. First method: not use model layer

  // app/controllers/UsersController.php: write in store()
  $validation = Validator::make(Input::all(), ['username' => 'required', 'password' => 'required']);
  if( $validation->fails() )
  {
    return Redirect::back()->withInput()->withErrors($validation->messages());
  }
// app/views/create.blade.php
@extends("layouts.default")

@section('content')
  <h1>Create New User</h1>
  
  {{ Form::open(["route" => "users.store"]) }}
    <div>
      {{ Form::label("username", 'Username: ') }}
      {{-- {{ Form::input("text", "username") }} --}}
      {{-- Form::checkbox("username") --}}
      {{ Form::text("username") }}
      {{ $errors->first('username', '<span class=error>:message</span>') }}
      
    </div>
    <div>
      {{ Form::label("password", 'Password: ') }}
      {{-- {{ Form::input("password", "username") }} --}}
      {{ Form::password("password") }}
      {{ $errors->first('password') }}
    </div>
    
    <div>
      {{ Form::submit("Create User") }}
    </div>
    
  {{ Form::close() }}
@stop

2. Second method: use model layer

// app/controllers/UsersController.php: write in store()
if( ! User::isValid(Input::all()) )
{
  return Redirect::back()->withInput()->withErrors(User::$errors);
}
// app/models/User.php: add the following lines
public static $rules = [
  'username' => 'required',
  'password' => 'required'
];
public static $errors;

public static function isValid($data)
{
  $validation = Validator::make($data, static::$rules);
  if($validation->passes())
  {
    return true;
  }
  
  static::$errors = $validation->messages();
  return false;
}