Comments (9)
It works for me perfectly. I can't help if I have nothing to work with.
If you can't be more specific with your code, please rollback uniquewith-validation
to an earlier version and tell what version change made it work again.
from uniquewith-validator.
I'm experiencing the same issue. Tried all 2.* versions of uniquewith-validator and some older 5.1.* versions of Laravel. The issue occured every time.
My validation rule looks like this: 'name' => 'required|unique_with:table,owner_id'
. The table requires the combination of "name" and "owner_id" to be unique.
The executed validation query checks for where
name= ? and
owner_idis null
. Because owner_id
is not present in the input it is set to null (by calling array_get
in line 84 in ValidatorExtension.php
).
Of course this statement always returns 0 rows and makes the validator returning true.
I'm not having "owner_id" in the input because the value is later set manually with the ID of the current authenticated user.
Any idea to fix this, besides modifying the input before passing it to validation?
from uniquewith-validator.
@lbausch You have to pass all values involved to the validator. That is the whole point of it. No workaround possible.
from uniquewith-validator.
@felixkiss Thank you for your reply - thats what I supposed already. Do you have any best practice for modifying the input in Form Requests?
from uniquewith-validator.
Yeah... I've test with normal validation from controller which is not from Form Request. From Form request, it doesn't work which means it always return true. Any idea? My laravel version is 5.1.
bty I love ur package. @felixkiss .
from uniquewith-validator.
Something like this:
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Auth;
class FooRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
$this->getInputSource()->set('user_id', Auth::user()->id);
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'test' => 'required',
];
}
}
Not ideal to set it in the authorize
method, but it didn't work in the constructor and I know that authorize
will be called at least once. You might find a better method to override and set your custom data.
Please post the relevant parts of your code (form request including rules and data you are trying to validate).
from uniquewith-validator.
Hi @felixkiss ...
here is mine.
// this one works.
// Controller.
public function store(Request $request)
{
$rules = array(
'car_type_id' => 'required|unique_with:cars,brand_id,model_year',
'brand_id' => 'required|integer',
'hscode' => 'required|numeric',
'model_year' => 'required|digits:4',
'engine_power' => 'required',
);
$validator = Validator::make($request->all(), $rules);
if($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
}
Car::create($request->all());
return redirect()->route('cars.index');
}
// this one doesn't work.
// Controller
public function store(CreateCarRequest $request)
{
Car::create($request->all());
return redirect()->route('cars.index');
}
// rules from Form Request.
public function rules()
{
return [
'car_type_id' => 'required|unique_with:cars,brand_id,model_year',
'brand_id' => 'required|integer',
'hscode' => 'required|numeric',
'model_year' => 'required|digits:4',
'engine_power' => 'required',
];
}
Now I have this error message.
Argument 3 passed to Illuminate\Validation\Factory::make() must be of the type array, null given, called in /home/sithuaung/Sites/projects/accounting/vendor/laravel/framework/src/Illuminate/Foundation/Http/FormRequest.php on line 83 and defined.
from uniquewith-validator.
@WebCrazy Are you overriding the messages
method in either CreateCarRequest
or App\Http\Requests\Request
?
from uniquewith-validator.
@felixkiss Ops...terribly yes. Now working. Thanks
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.