php - using unique rule of laravel 4 on updating database records -
i have table weapons have columns weaponid, weaponname, wstock, wdesc
in update function inside controller, have set of rules
public function c_updatesystemuser($id) { $rules = array( 'weaponname' => 'required|min:2|max:50|regex:/^[a-za-z0-9\-\s]+$/|unique:weapontbl,weaponname,' . $id, 'wstock' => 'required|numeric', 'wdesc' => 'required|min:1|max:100|regex:/^[a-za-z0-9\-\s]+$/' ); //other stuff }
when updated , changed wstock having problems because saying weaponname existed. used unique rule
unique:weapontbl,weaponname,' . $id,
because wanted except record im working on when tested i'am having these errors
column not found: 1054 unknown column 'id' in 'where clause' (sql: select count(*) aggregate `weapontbl` `weaponname` = unicorn , `id` <> 1)
why using id whereas don't have 'id' in table weaponid? there way work around this?
inside weapon class need change primary key:
class weapon extends eloquent { protected $primarykey = 'weaponid'; }
and change unique rule to:
unique:weapontbl,weaponname,' . $id . ',weaponid'
Comments
Post a Comment