make category types extendible

This commit is contained in:
Denis Duliçi
2021-02-18 11:54:01 +03:00
parent 09dde2847f
commit c074be895f
3 changed files with 107 additions and 63 deletions

28
app/Traits/Categories.php Normal file
View File

@ -0,0 +1,28 @@
<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait Categories
{
public function getCategoryTypes()
{
$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;
}
}