Code Monkey home page Code Monkey logo

Comments (24)

felixkiss avatar felixkiss commented on August 28, 2024 1

One more try. Edit vendor/felixkiss/uniquewith-validator/src/Felixkiss/UniqueWithValidator/UniqueWithValidatorServiceProvider:

    public function boot()
    {
        $this->package('felixkiss/uniquewith-validator');

        var_dump(get_class($this->app['validator']->make(array(), array())));
        // Registering the validator extension with the validator factory
        $this->app['validator']->resolver(function($translator, $data, $rules, $messages)
        {
            // Set custom validation error messages
            $messages['unique_with'] = $translator->get('uniquewith-validator::validation.unique_with');

            return new ValidatorExtension($translator, $data, $rules, $messages);
        });
        var_dump(get_class($this->app['validator']->make(array(), array())));
    }

and run php artisan. What does it print out?

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024 1

Ok, I think I got it. Do composer update and delete app/storage/meta/services.json if it exists.

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

Can you please provide more info. It works for me, so I need to get a similar environment to yours.

How does your composer.json look like? (other packages, etc.)

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

Im working in Linux machine.
Here is my composer.js

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "require": {
        "laravel/framework": "4.0.*",
        "way/generators": "1.0.*@dev",
        "twitter/bootstrap": "dev-master",
        "zizaco/entrust": "dev-master",
        "felixkiss/uniquewith-validator": "dev-master"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/libraries"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan optimize"
        ],
        "pre-update-cmd": [
            "php artisan clear-compiled"
        ],
        "post-update-cmd": [
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "dev"
}

I have a BaseModel that extends Eloquent.

class BaseModel extends Eloquent {
    public $errors;

    public static function boot(){
        parent::boot();
        static::saving(function($obj){
            return $obj->validate();
        });
    }
    public function validate()
    {
        dd($this->attributes);
        $validation = Validator::make($this->attributes, static::$rules);

        if($validation->passes()) return true;

        // if validation fails, get messages back
        $this->errors = $validation->messages();
        return false;
    }
}

... and all my models extend this class.
Example model is like this:

class Thing extends BaseModel{
        protected $guarded = [];
    protected static $rules = array(
        'name' => 'required',
        'email' => 'required|email'
    );
}

So whenever in controller i do:

$thing = new Thing;
$thing->name = '';
$thing->email = '[email protected]';
$thing->save();

the validation will start. It works fine with default validator.
If i change it to:

    protected static $rules = array(
        'name' => 'required|unique_with:things,email',
        'email' => 'required|email'
    );

i get the error.

Thanks.

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

Seems like there is some other problem than with your package.
I tried to create custom validator in app/libraries, pasted in your code, made some changes and added libraries to autoload. It still gives me the same error. So i guess the problem is somewhere else.
Thanks for the package.
Really hope to get it working.

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

Try this:

class BaseModel extends Eloquent {
    // ...
    public function validate()
    {
        dd($this->attributes);
        $validation = Validator::make($this->attributes, static::$rules);
        var_dump(get_class($validation));

        if($validation->passes()) return true;

        // if validation fails, get messages back
        $this->errors = $validation->messages();
        return false;
    }
}

What is the actual class of the Validator? Should be Felixkiss\UniqueWithValidator\ValidatorExtension

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

Can't do var_dump there, it gets error before and dies.

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

Weird. Does dd($this->attributes); get printed?

If so, you could try to move some echo statement from top to bottom in make() of vendor/laravel/framework/src/Illuminate/Validation/Factory.php to see what line of code produces the error.

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

Yes, dd($this->attributes); got printed correctly.
In make() the $validator class before return is "Illuminate\Validation\Validator", so i think there is some problems in MY project with loading classes. But what, i have no idea! (quite new to laravel also)

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

You did add Felixkiss\UniqueWithValidator\UniqueWithValidatorServiceProvider to the providers array in config/app.php, right?

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

Yep, i did.

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

Seems like ServiceProvider does not register ValidatorExtension class.

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

hmm, now im totally confused:
php artisan serve
string(31) "Illuminate\Validation\Validator"
string(48) "Felixkiss\UniqueWithValidator\ValidatorExtension"
Laravel development server started on http://localhost:8000

Looks as it should i believe.

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

Yep, working now!

from uniquewith-validator.

hanneskaljuste avatar hanneskaljuste commented on August 28, 2024

Thanks a lot!

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

💯 👍

from uniquewith-validator.

adis-io avatar adis-io commented on August 28, 2024

I have got the same error in 4.1

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

@adisos Did you follow all the steps described above? What are your results?

Without more information I can't even make an educated guess.

from uniquewith-validator.

adis-io avatar adis-io commented on August 28, 2024

sorry, dude, I was using https://github.com/FrozenNode/Laravel-Administrator

just now checked out of administrator's scope and it's worked

from uniquewith-validator.

sumanta-ghosh avatar sumanta-ghosh commented on August 28, 2024

Yesterday it was working fine now I run composer update then I got this issue

{"error":{"type":"BadMethodCallException","message":"Method [validateUniqueWith] does not exist.","file":"E:\\PROJECT DEPT\\Server\\htdocs\\apps\\onlineworkforce\\laravel\\vendor\\laravel\\framework\\src\\Illuminate\\Validation\\Validator.php","line":2564}}

As per instruction in previous comment I add those two line and run php artisan I got this bellow oputput :

O:\laravel>php artisan
string(31) "Illuminate\Validation\Validator"
string(48) "Felixkiss\UniqueWithValidator\ValidatorExtension"
Laravel Framework version 4.2.17

from uniquewith-validator.

Starkmann avatar Starkmann commented on August 28, 2024

I have the same error on larvel 5.3.

The boot method i called since i can dd there

from uniquewith-validator.

bosz avatar bosz commented on August 28, 2024

Hey dude, i have followed up the discussion but still getting
BadMethodCallException in Validator.php line 3295:
Method [validateUniqueWith] does not exist.

composer.json file has the package, i have added the provider, here is my validation rule
`
$rules = [
'house_id' => 'required|unique_with:caretaker_assign_house,caretaker_id',
'caretaker_id' => 'required',
];

    $validator = Validator::make($request->all(), $rules);

    if($validator->fails()) {
        die();
        return Redirect::back()->withErrors($validator);
    }

`
Help pls

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

What version are you using?

from uniquewith-validator.

arturpasnik avatar arturpasnik commented on August 28, 2024

Laravel 5.4 happen to me
this helped:

composer update
artisan config:cache
artisan cache:clear
artisan optimize

from uniquewith-validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.