make category types extendible
This commit is contained in:
parent
09dde2847f
commit
c074be895f
@ -11,9 +11,11 @@ use App\Jobs\Setting\CreateCategory;
|
||||
use App\Jobs\Setting\DeleteCategory;
|
||||
use App\Jobs\Setting\UpdateCategory;
|
||||
use App\Models\Setting\Category;
|
||||
use App\Traits\Categories as Helper;
|
||||
|
||||
class Categories extends Controller
|
||||
{
|
||||
use Helper;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
@ -26,12 +28,7 @@ class Categories extends Controller
|
||||
|
||||
$transfer_id = Category::transfer();
|
||||
|
||||
$types = collect([
|
||||
'expense' => trans_choice('general.expenses', 1),
|
||||
'income' => trans_choice('general.incomes', 1),
|
||||
'item' => trans_choice('general.items', 1),
|
||||
'other' => trans_choice('general.others', 1),
|
||||
]);
|
||||
$types = $this->getCategoryTypes();
|
||||
|
||||
return $this->response('settings.categories.index', compact('categories', 'types', 'transfer_id'));
|
||||
}
|
||||
@ -53,12 +50,7 @@ class Categories extends Controller
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$types = [
|
||||
'expense' => trans_choice('general.expenses', 1),
|
||||
'income' => trans_choice('general.incomes', 1),
|
||||
'item' => trans_choice('general.items', 1),
|
||||
'other' => trans_choice('general.others', 1),
|
||||
];
|
||||
$types = $this->getCategoryTypes();
|
||||
|
||||
return view('settings.categories.create', compact('types'));
|
||||
}
|
||||
@ -128,12 +120,7 @@ class Categories extends Controller
|
||||
*/
|
||||
public function edit(Category $category)
|
||||
{
|
||||
$types = [
|
||||
'expense' => trans_choice('general.expenses', 1),
|
||||
'income' => trans_choice('general.incomes', 1),
|
||||
'item' => trans_choice('general.items', 1),
|
||||
'other' => trans_choice('general.others', 1),
|
||||
];
|
||||
$types = $this->getCategoryTypes();
|
||||
|
||||
$type_disabled = (Category::where('type', $category->type)->count() == 1) ?: false;
|
||||
|
||||
|
28
app/Traits/Categories.php
Normal file
28
app/Traits/Categories.php
Normal 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;
|
||||
}
|
||||
}
|
@ -88,4 +88,33 @@ return [
|
||||
],
|
||||
'contact_type' => 'vendor',
|
||||
],
|
||||
|
||||
// Categories
|
||||
'category' => [
|
||||
'income' => [
|
||||
'alias' => '',
|
||||
'translation' => [
|
||||
'prefix' => 'general',
|
||||
],
|
||||
],
|
||||
'expense' => [
|
||||
'alias' => '',
|
||||
'translation' => [
|
||||
'prefix' => 'general',
|
||||
],
|
||||
],
|
||||
'item' => [
|
||||
'alias' => '',
|
||||
'translation' => [
|
||||
'prefix' => 'general',
|
||||
],
|
||||
],
|
||||
'other' => [
|
||||
'alias' => '',
|
||||
'translation' => [
|
||||
'prefix' => 'general',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user