Custom Validation
Hi Laracasts, I'm building validation into my application right now. I'd like to add custom validation. I've added a service provider.
<?php
namespace Uma\Providers;
use Validator;
use Illuminate\Support\ServiceProvider;
use Uma\Services\ValidationService;
class ValidationServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('foo', function($attribute, $value, $parameters) {
return $value == 'foo';
});
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}
I also added the provider to config/app.php.
Uma\Providers\ValidationServiceProvider::class,
And I've added my error message to resources/lang/en/validation.php.
"foo" => "Your input was invalid!",
Here is how I call validation in the controller.
$validator = Validator::make($request->all(), ['foo' => 'foo']);
But when I hit the site, it doesn't validate.
curl "http://domain.com/route?foo=bar"
This returns my data instead of a validation error. I've been following the custom validation rules section of the validation documentation. I also read up on service providers and I think I know how they work but they are still fairly new to me. Am I missing something?
Please or to participate in this conversation.