robsonvn / laravel-couchdb

A CouchDB based Eloquent model and Query builder for Laravel
56 stars 28 forks source link

Laravel Requests - Rules: UNIQUE #13

Closed edukmattos closed 6 years ago

edukmattos commented 6 years ago

HI ! Is this package works with Laravel Requests Rules ? My script: public function rules() { return [ 'name' => 'required|max:40|unique:users_collection,name,'.$this->_id.',id,deleted_at,NULL', 'fullname' => 'required|max:100|unique:users_collection,fullname,'.$this->_id.',id,deleted_at,NULL', 'email' => 'required|email|max:50|unique:users_collection,email,'.$this->_id.',id,deleted_at,NULL', 'role_id' => 'required' ]; } I created the same users and validation dont works ! Any suggestion ?

edukmattos commented 6 years ago

Sorry. I founded my error: 'name' => 'required|max:40|unique:users_collection,name,'.$this->_id.',_id,deleted_at,NULL',

edukmattos commented 6 years ago

My problem is that the laravel validation differentiates between upper and lower case characters, ie, CAR is different of the car. I need validation to consider CAR = car. Any suggestions ?

edukmattos commented 6 years ago

My problem is that the laravel validation differentiates between upper and lower case characters, ie, CAR is different of the car. I need validation to consider CAR = car. Any suggestions ?

edukmattos commented 6 years ago

Hi ! With MySQL it works and CouchDB does not.

robsonvn commented 6 years ago

Hi @ecmattos,

I don't see this as a problem. CouchDB treat the fields as case-sensitive, hence CAR is not equals car.

Why don't you treat your inputs before validating?

robsonvn commented 6 years ago

Either you start to store your data lower or upper case only or you will have to treatment your input before validating.

Maybe this can help you

'name' => Rule::unique('name')->where(function ($query) { $query->where('_id', strtoupper('car')); })

edukmattos commented 6 years ago

It worked ! Thanks !