use App\Enums\AccountType;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Livewire\Component;
class AccountsTable extends Component
{
//
public array $data = [
'name' => '',
'type' => AccountType::STOCKS,
'currency' => 1
];
//
public function createAccount()
{
Validator::make($this->data, [
'name' => ['required', 'string'],
'type' => ['required', Rule::in(Account::TYPES)]
]);
auth()->user()->accounts()->create([
'name' => $this->data['name'],
'type' => $this->data['type'],
'currency_id' => Currency::find($this->data['currency'])->id
]);
return $this->redirect('dashboard');
}
//
}