akaunting/app/Traits/Categories.php
2022-07-21 01:07:55 +03:00

47 lines
1.0 KiB
PHP

<?php
namespace App\Traits;
use App\Models\Setting\Category;
use Illuminate\Support\Str;
trait Categories
{
public function getCategoryTypes(): array
{
$types = [];
$configs = config('type.category');
foreach ($configs as $type => $attr) {
$plural_type = Str::plural($type);
$name = $attr['translation']['prefix'] . '.' . $plural_type;
if (!empty($attr['alias'])) {
$name = $attr['alias'] . '::' . $name;
}
$types[$type] = trans_choice($name, 1);
}
return $types;
}
public function getCategoryWithoutChildren(int $id): mixed
{
return Category::getWithoutChildren()->find($id);
}
public function getTransferCategoryId(): mixed
{
return Category::other()->pluck('id')->first();
}
public function isTransferCategory(): bool
{
$id = $this->id ?? $this->category->id ?? $this->model->id ?? 0;
return $id == $this->getTransferCategoryId();
}
}