Skip to content

Validator Error: Forcing A Unique Rule To Ignore A Given ID fails if primary key is not named "id" #3800

@fireproofsocks

Description

@fireproofsocks

To reproduce, define some validation rules that use the "unique" rule:

$rules = array(
    'username'  =>  'required|min:5|unique:users,username,123',
);

$validation = Validator::make(Input::all(),$rules);
if($validation->passes()) {
      return 'Ok.';
}

The rule fails to generate the proper query if the referenced table does not rely on a primary key named "id". E.g. if your table is defined using a primary key of "user_id", the query and validation rule fails

    Schema::create('users', function(Blueprint $table) {
        $table->increments('user_id')->unsigned();
        // ... etc...

Even if the model includes

protected $primaryKey = 'user_id';

Laravel version 4.1.23

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions