Comments (24)
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.
Ok, I think I got it. Do composer update
and delete app/storage/meta/services.json
if it exists.
from uniquewith-validator.
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.
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.
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.
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.
Can't do var_dump there, it gets error before and dies.
from uniquewith-validator.
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.
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.
You did add Felixkiss\UniqueWithValidator\UniqueWithValidatorServiceProvider
to the providers
array in config/app.php
, right?
from uniquewith-validator.
Yep, i did.
from uniquewith-validator.
Seems like ServiceProvider does not register ValidatorExtension class.
from uniquewith-validator.
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.
Yep, working now!
from uniquewith-validator.
Thanks a lot!
from uniquewith-validator.
💯 👍
from uniquewith-validator.
I have got the same error in 4.1
from uniquewith-validator.
@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.
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.
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.
I have the same error on larvel 5.3.
The boot method i called since i can dd there
from uniquewith-validator.
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.
What version are you using?
from uniquewith-validator.
Laravel 5.4 happen to me
this helped:
composer update
artisan config:cache
artisan cache:clear
artisan optimize
from uniquewith-validator.
Related Issues (20)
- It only works for the current request HOT 4
- Bad method call HOT 1
- Validation fails when updating composite keys with ignore HOT 1
- Using that validation rule with renamed fileds
- Update for Laravel 6.0 HOT 1
- Can't seem to get it working for Polymorph fields HOT 2
- How to add deleted_at, NULL HOT 2
- Update for Laravel 8.0 HOT 10
- Please add support for PHP 8 HOT 1
- Ignore is not working in array validation HOT 1
- unique_with can't validation on multiple column
- Migrate test suite from Travis to Github Actions HOT 1
- Wrong locale set on app
- Compatibility Issue with laravel 9 php 8.X HOT 11
- Counter-intuitive deleted_at in rules
- Ignoring deleted items not working properly
- Laravel 5.4 : doesn't work on updating ! HOT 5
- its not working with database connection HOT 1
- Giving duplicate entry in every new entry HOT 2
- Is there a possibility of a validator plugin for exist_with? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uniquewith-validator.