Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

mateusjatenee/crypto-tracker

48 stars
3 code files
View mateusjatenee/crypto-tracker on GitHub

app/Models/Account.php

Open in GitHub
use 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 GitHub
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');
}
//
}

app/Enums/AccountType.php

Open in GitHub
class AccountType
{
const CASH = 'cash';
const CRYPTO = 'crypto';
const STOCKS = 'stocks';
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.