Support the ongoing development of Laravel.io →
posted 7 years ago
Validation
Last updated 2 years ago.
0

Hi again, i has found them idea to write a custom validation rule. Fine. But now, after hours of searching, i'm totaly confused. I use laravel 5.3,

I had a try in AppServiceProvider, in the boot section like that: \Illuminate\Support\Facades\Validator::extend('path', function ($attribute, $value, $parameters, $validator) { return false; });

At this point: i am not sure,

  1. where to put my rule
  2. which of the many validators to use (\Dotenv\Validator::, \Illuminate\Contracts\Validation\Validator::, \Illuminate\Validation\Validator:: or \Illuminate\Support\Facades\Validator::
  3. how to call my validation

Please help :-)

Jan

0

You can get all about how to create custom validator with laravel at How can you create Custom Validation recipe in Laravel 5.x.

0

Hi, thanks for your hint, but its not working (at me). I had create a first this 2 Classes:

namespace App\Validator;
use Illuminate\Validation\Validator;
class CustomValidator extends Validator {
	public function ValidateFilepath($attribute, $value, $parameters){
		return $value == "bla";
	}
}

namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Validator\CustomValidator;
class ValidationServicePovider extends ServiceProvider {
    public function boot(){
        $this->app->validator->resolver(function ($translator, $data,$rules,$messages){
			return new CustomValidator($translator, $data,$rules,$messages);
		});
    }
...

also i had register the ValidationServicePovider in /config/app.php

But now nothing happen, when i call it liek that:

$this->validate($request, ['path' => 'required:filepath']);

I had try "filepath" in some cases, no results (and no errors)

Jan

Last updated 7 years ago.
0

Can anyone help me out of this ?

Jan

0

Sign in to participate in this thread!

Eventy

Your banner here too?

bforpc bforpc Joined 14 Dec 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.