I am currently trying to add a validation for the customer_no in the companies table.
public function rules()
{
$id = Company::where('customer_no', '=', $this->get('customer_no'))->first();
$id = $id['attributes']['id'];
return [
'customer_no' => 'required|unique:companies,customer_no,'.$id,
];
}
After adding a new company with an already existing customer_no I get the following error message from the unique database migration.
SQLSTATE[23000]: Integrity constraint violation:
1062 Duplicate entry 'abc' for key 'companies_customer_no_unique'
(SQL: update `companies` set `customer_no` = abc, `updated_at` = 2016-03-15 14:50:28 where `id` = 1)
But instead it should redirect me to the previous page and show the error message. This is already working for the required field and the variable $id contains the id of the company (checked with var_dump).
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire