added route name and id attributes

This commit is contained in:
Denis Duliçi
2020-09-03 10:42:53 +03:00
parent 6c8e98ee74
commit cf2c8f0f05
2 changed files with 42 additions and 14 deletions

View File

@ -291,4 +291,36 @@ class Transaction extends Model
{
return $value ?? trans_choice('general.' . Str::plural($this->type), 1);
}
/**
* Get the route name.
*
* @return string
*/
public function getRouteNameAttribute($value)
{
if ($value) {
return $value;
}
if ($this->isIncome()) {
return !empty($this->document_id) ? 'invoices.show' : 'revenues.edit';
}
if ($this->isExpense()) {
return !empty($this->document_id) ? 'bills.show' : 'payments.edit';
}
return 'transactions.index';
}
/**
* Get the route id.
*
* @return string
*/
public function getRouteIdAttribute($value)
{
return $value ?? $this->document_id ?? $this->id;
}
}