Code Monkey home page Code Monkey logo

Comments (7)

felixkiss avatar felixkiss commented on August 28, 2024

uniquewith-validator is intended as a Laravel validation rule for dealing with multi-column UNIQUE definitions in your SQL database. Therefore, the database will raise an error, if you attempt to insert a new record into the table anyways.

If you don't have a UNIQUE index in your database table, there could be a flag on the uniquewith-rule that tells it to ignore the deleted_at field. I will think about that one.

In the mean time, use this as a workaround:

Route::get('users/validate', function()
{
    $rules = array(
        'first_name' => 'required|unique_with:users,last_name,deleted_at',
        'last_name' => 'required',
    );

    $input = array(
        'first_name' => 'Felix',
        'last_name' => 'Kiss',
        'deleted_at' => null,
    );

    $validator = Validator::make($input, $rules);

    // Validation will fail on every user name combination, which exists, but is not 
    // deleted while passing on all user name combination, if there already is an 
    // existing, deleted record with the same combination.
    if($validator->fails())
    {
        var_dump($validator->errors());
        exit();
    }

    return "success!";
});

from uniquewith-validator.

rawaludin avatar rawaludin commented on August 28, 2024

Have you solved it?
I really love your package and want to combine with softDelete.

Thanks.. :)

from uniquewith-validator.

rawaludin avatar rawaludin commented on August 28, 2024

I have almost same problem.
Is it possible to ignore with multiple field?
For example, i activated softDelete. So, when I update i want to ignore id and deleted_at row. How should I do that?

from uniquewith-validator.

dadhiramp avatar dadhiramp commented on August 28, 2024

I am using Laravel 5 and trying to ignore multiple fields validation using the rule

return [
'permission_id' => 'required',
'role_id' => 'required|unique_with:permission_role,permission_id,'.Input::get('role_id').'=role_id,'.Input::get('permission_id').'=permission_id'
];

however it turns up saying :

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: update permission_role set permission_id = 2 where id is null)

There is no mention of id, instead i have used custom_id_column as per document,
for insert case

return [
'permission_id' => 'required',
'role_id' => 'required|unique_with:permission_role,permission_id'
];

works fine, however having trouble with the ignore case for update.

Thanks

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

@dadhiramp

  1. the error doesn't look to be referring to the validator but rather the update statement following a successful validation.

  2. specifying more than one ignore column is currently not supported (I think Laravel's PresenceVerifier, which is used in the background, doesn't support multiple ignore columns either).

If you are updating a model, you can use the id as the ignore column. Something like:

'role_id' => 'required|unique_with:permission_role, permission_id, ' . $model->id . ' = id',

from uniquewith-validator.

dadhiramp avatar dadhiramp commented on August 28, 2024

Thanks for the prompt response felixkiss ... yes the error is indeed after the validation, seems like i need to add up extra column for it then.

Regards

👍

from uniquewith-validator.

felixkiss avatar felixkiss commented on August 28, 2024

Thanks to #41 the README now documents how to use this package with soft deletes

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.