Code Monkey home page Code Monkey logo

Comments (9)

felixkiss avatar felixkiss commented on August 28, 2024

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.

lbausch avatar lbausch commented on August 28, 2024

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 wherename= ? andowner_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.

felixkiss avatar felixkiss commented on August 28, 2024

@lbausch You have to pass all values involved to the validator. That is the whole point of it. No workaround possible.

from uniquewith-validator.

lbausch avatar lbausch commented on August 28, 2024

@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.

sithuaung avatar sithuaung commented on August 28, 2024

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.

felixkiss avatar felixkiss commented on August 28, 2024

@lbausch

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.


@WebCrazy

Please post the relevant parts of your code (form request including rules and data you are trying to validate).

from uniquewith-validator.

sithuaung avatar sithuaung commented on August 28, 2024

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.

felixkiss avatar felixkiss commented on August 28, 2024

@WebCrazy Are you overriding the messages method in either CreateCarRequest or App\Http\Requests\Request?

from uniquewith-validator.

sithuaung avatar sithuaung commented on August 28, 2024

@felixkiss Ops...terribly yes. Now working. Thanks

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.