Tax type compound just add once.

This commit is contained in:
Cüneyt Şentürk
2020-12-22 14:47:50 +03:00
parent 1411bd879c
commit 654f7bbb2c
6 changed files with 45 additions and 7 deletions

View File

@ -23,10 +23,25 @@ class Tax extends FormRequest
*/
public function rules()
{
// Check if store or update
if ($this->getMethod() == 'PATCH') {
$id = is_numeric($this->tax) ? $this->tax : $this->tax->getAttribute('id');
} else {
$id = null;
}
$company_id = $this->request->get('company_id');
$type = 'required|string';
if (!empty($this->request->get('type')) && $this->request->get('type') == 'compound') {
$type .= '|unique:taxes,NULL,' . $id . ',id,company_id,' . $company_id . ',type,compound,deleted_at,NULL';
}
return [
'name' => 'required|string',
'rate' => 'required|min:0|max:100',
'type' => 'required|string',
'type' => $type,
'enabled' => 'integer|boolean',
];
}