crudbooster icon indicating copy to clipboard operation
crudbooster copied to clipboard

Bug Fix edit-save for unique validation

Open robinhoo1973 opened this issue 6 years ago • 2 comments

  • CRUDBooster latest

  • Laravel 5.6

  • Cannot save edit data with unique validation of unique field not changed

  • without any change of the edit data and press save should successfully pass the save, but error page shows without any clue to debug

  • create a table with primary key not named as id like supp_id(supplier ID autoincreased), and an unique field like supp_name(supplier name), setup form accordingly and add a record, after add try to edit it without any change and press save.

  • my solution is For problem of primary key name is not id In /vendor/crocodicstudio/crudbooster/src/controllers/CBController.php
    Change line 935 from empty line to "$uniqueRebuild[] = CB::findPrimaryKey($uniqueTable);"

         Comment line 938 within the function validation to add the case of primary key not named as id.
    

For submit not directed to right url with row id followed by edit-save/$id which caused by the primary key is not named as id. In /vendor/crocodicstudio/crudbooster/src/views/default/form.blade.php Change line 23 from $action = (@$row) ? CRUDBooster::mainpath("edit-save/$row->id") : CRUDBooster::mainpath("add-save"); To $action = (@$row) ? CRUDBooster::mainpath("edit-save/$id") : CRUDBooster::mainpath("add-save");

robinhoo1973 avatar Jun 24 '18 08:06 robinhoo1973

Maybe litle update.

$id = property_exists($row,"id") ? $row->id : $id; $action = (@$row) ? CRUDBooster::mainpath("edit-save/$id") : CRUDBooster::mainpath("add-save");

rizkynich avatar Nov 02 '18 06:11 rizkynich

public function hook_before(&$postdata) { //This method will be execute before run the main process

			$rule = [];
		    $rule['email'] = 'unique:cms_users,email,'.$postdata['id'];
			$rule['password_confirmation'] = 'required_with:password|same:password|min:6';
			CRUDBooster::valid($rule);
			
			
	    }

umedstrivedge avatar Nov 02 '21 09:11 umedstrivedge