laravel/framework — pull request #2449 by andreluizmorita (2013-10-09 19:28:06+00:00)
Title: Added parameter $customAttributes in Factory and Validator to use the Validator::make()

This adjustment is to further simplify the use of the Validator centralizing message rules and attributes return the model itself or the controller where the Validator is being used while avoiding adjust the file en / validation.php the vector attributer = array (), example:
```php5

// Controller
class FormController extends BaseController {

public function getIndex()
{
return View::make('forms.validatorAttributes');
}

public function postValidator()
{
try
{
$validator = Validator::make(Input::all(),
array(
'empresa_id' => 'required',
'nome' => 'required|min:5',
'email' => 'required|email|unique:contatos',
'telefone' => 'required|min:7',
'endereco' => 'required'
'senha' => 'required'
),
array(
'empresa_id.required' => "The company's records is mandatory for the contact to be added.",
'email.unique' => "This email has been taken, if it's yours you could try to " . HTML::linkRoute('login', 'login')
),
array(
'endereco' => 'endereço'
'email' => 'e-mail'
)
);

/* Or more simple if to use your parameters in Model. Once you define all parameters and can reuse them in different parter system and when editing these parameters in the model they already estaram correct in other parts of the system where they are used
*/
$validator = Validator::make(
Input::all(),
Contato::$rules,
Contato::$message,
Contato::$customAttributes
);

if($validator->fails())
{
throw new Exception("Fails");
}
else
{
// Save your input
}
}
catch(Exception $e)
{
return Redirect::to('your_form')->withInput()->withErrors($validator);
}
}
}

// Model
class Contato extends Eloquent
{
protected $guarded = array('id');

public static $rules = array(
'empresa_id' => 'required',
'nome' => 'required|min:5',
'email' => 'required|email|unique:contatos',
'telefone' => 'required|min:7',
'endereco' => 'required'
'senha' => 'required'
);

public static $messages = array(
'empresa_id.required' => "The company's records is mandatory for the contact to be added.",
'email.unique' => "This email has been taken, if it's yours you could try to " .
HTML::linkRoute('login', 'login') . '.',
);

public static $customAttributes = array(
'endereco' => 'endereço'
'email' => 'e-mail'
);
}
```