Skip to content

Instantly share code, notes, and snippets.

@luceos
Created February 13, 2015 09:26
Show Gist options
  • Save luceos/cb4e8655d64c3fe7657e to your computer and use it in GitHub Desktop.
Save luceos/cb4e8655d64c3fe7657e to your computer and use it in GitHub Desktop.
extending laravel 4 validation
<?php namespace Vendor\Package;
use Illuminate\Validation\Validator;
class ExtendedValidator extends Validator
{
// use validation rule "foo" to use
public function validateFoo($attribute, $value, $parameters)
{
return $value == "foo";
}
// add more validation rules
}
/**
* In your service provider, registered in app/config/app.php add
* @info please note this is a different php file!
*/
//.. opening php tag and namespace definition see above
use Illuminate\Support\ServiceProvider;
class PackageServiceProvider extends ServiceProvider
{
public function register()
{
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new ExtendedValidator($translator, $data, $rules, $messages);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment