-
app/Models/Account.php
Open in GitHubuse App\Contracts\HasPositions; use App\Enums\AccountType; use Illuminate\Database\Eloquent\Model; class Account extends Model implements HasPositions { // public const TYPES = [ AccountType::CRYPTO => 'Crypto', AccountType::STOCKS => 'Stocks', AccountType::CASH => 'Bank' ]; // }
-
app/Http/Livewire/AccountsTable.php
Open in GitHubuse 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'); } // }
-
app/Enums/AccountType.php
Open in GitHubclass AccountType { const CASH = 'cash'; const CRYPTO = 'crypto'; const STOCKS = 'stocks'; }