57 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2022-06-01 10:15:55 +03:00
<?php
namespace App\View\Components\Form\Group;
use App\Abstracts\View\Components\Form;
2022-08-05 10:59:23 +03:00
use App\Models\Setting\Tax as Model;
2022-06-01 10:15:55 +03:00
class Tax extends Form
{
public $type = 'tax';
public $path;
public $field;
2022-08-05 10:59:23 +03:00
public $taxes;
2022-06-01 10:15:55 +03:00
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|string
*/
public function render()
{
if (empty($this->name)) {
2022-08-05 10:59:23 +03:00
$this->name = 'tax_id';
2022-06-01 10:15:55 +03:00
}
2022-08-05 10:59:23 +03:00
$this->path = route('modals.taxes.create');
2022-06-01 10:15:55 +03:00
$this->field = [
2022-08-05 10:59:23 +03:00
'key' => 'id',
'value' => 'title'
2022-06-01 10:15:55 +03:00
];
$this->taxes = Model::enabled()->orderBy('name')->get()->pluck('title', 'id');
2022-08-05 10:59:23 +03:00
$tax_id = old('tax.id', old('tax_id', null));
if (! empty($tax_id)) {
$this->selected = $tax_id;
if (! $this->taxes->has($tax_id)) {
2022-08-05 10:59:23 +03:00
$tax = Model::find($tax_id);
$this->taxes->put($tax->id, $tax->title);
2022-08-05 10:59:23 +03:00
}
}
2022-06-01 10:15:55 +03:00
if (empty($this->selected) && empty($this->getParentData('model'))) {
2022-08-05 10:59:23 +03:00
$this->selected = setting('default.tax');
2022-06-01 10:15:55 +03:00
}
return view('components.form.group.tax');
}
}