Check invoice model props in validation to ensure cancelled invoices cannot be mutated

This commit is contained in:
David Bomba
2025-05-12 19:36:31 +10:00
parent 0ca1e378bf
commit 0a8ad8efc5
2 changed files with 10 additions and 19 deletions

View File

@@ -67,7 +67,16 @@ class UpdateInvoiceRequest extends Request
$rules['tax_name1'] = 'bail|sometimes|string|nullable';
$rules['tax_name2'] = 'bail|sometimes|string|nullable';
$rules['tax_name3'] = 'bail|sometimes|string|nullable';
$rules['status_id'] = 'bail|sometimes|not_in:5'; //do not allow cancelled invoices to be modfified.
$rules['status_id'] = [
'bail',
'sometimes',
'not_in:5',
function ($attribute, $value, $fail) {
if ($this->invoice->status_id == 5) {
$fail(ctrans('texts.locked_invoice'));
}
}
];
$rules['exchange_rate'] = 'bail|sometimes|numeric';
$rules['partial'] = 'bail|sometimes|nullable|numeric';
$rules['amount'] = ['sometimes', 'bail', 'numeric', 'max:99999999999999'];

View File

@@ -103,7 +103,6 @@ class BaseModel extends Model
return $this->encodePrimaryKey($this->id);
}
public function shouldBeSearchable()
{
return config('scout.driver') === 'elastic';
@@ -114,23 +113,6 @@ class BaseModel extends Model
return (new Carbon($value))->format('Y-m-d');
}
// public function __call($method, $params)
// {
// $entity = strtolower(class_basename($this));
// if ($entity) {
// $configPath = "modules.relations.$entity.$method";
// if (config()->has($configPath)) {
// $function = config()->get($configPath);
// return call_user_func_array([$this, $function[0]], $function[1]);
// }
// }
// return parent::__call($method, $params);
// }
/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder