VoucherController.php
public function store(Request $request, Voucher $voucher)
{
$validate = $this->voucher_repo->validateType($request);
if ($validate) {
$this->voucher_repo->addAction($request, $voucher);
Session::flash('flash', 'Successfully add voucher');
} else {
return redirect()
->back()
->withError('Persentase Voucher tidak boleh lebih dari sama dengan 100%')->withInput();
}
return redirect('voucher');
}
Voucher Repository.php
public function addAction($request, $voucher)
{
$user = json_encode($request['user']);
$startDate = date('Y-m-d', strtotime($request['start_date']));
$endDate = date('Y-m-d', strtotime($request['end_date']));
$attr = [
"voucher_code" => $request['voucher_code'],
"discount_type" => $request['discount_type'],
"discount_value" => $request['discount_value'],
'minimum_payment' => $request['minimum_payment'],
'quota' => $request['quota'],
"start_date" => $startDate,
"end_date" => $endDate,
"user" => $user
];
$locales = config('locales');
foreach ($locales as $key => $value) {
$voucher->translateOrNew($key)->description = $request->description[$key];
}
$voucher->fill($attr);
$voucher->save();
}
laravel.log
[2019-11-11 11:27:55] development.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' (SQL: insert into voucher_translations (locale, description, voucher_id, updated_at, created_at) values (en, New Discount, 7, 2019-11-11 11:27:54, 2019-11-11 11:27:54)) {"userId":1,"exception":"[object] (Illuminate\Database\QueryException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' (SQL: insert into voucher_translations (locale, description, voucher_id, updated_at, created_at) values (en, New Discount, 7, 2019-11-11 11:27:54, 2019-11-11 11:27:54)) at C:\xampp\htdocs\sesa\86\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664, Doctrine\DBAL\Driver\PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' at
This is strange since I do not feel like calling voucher_translations model.
I don't know if there is something to do with the package:
https://packagist.org/packages/dimsav/laravel-translatable
I search the vendor and still do not find the voucher_translation