Initial commit
This commit is contained in:
41
app/Models/User.php
Normal file
41
app/Models/User.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasOne<Wallet>
|
||||
*/
|
||||
public function wallet(): HasOne
|
||||
{
|
||||
return $this->hasOne(Wallet::class);
|
||||
}
|
||||
}
|
31
app/Models/Wallet.php
Normal file
31
app/Models/Wallet.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Wallet extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* @return BelongsTo<User>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<WalletTransaction>
|
||||
*/
|
||||
public function transactions(): HasMany
|
||||
{
|
||||
return $this->hasMany(WalletTransaction::class);
|
||||
}
|
||||
}
|
43
app/Models/WalletTransaction.php
Normal file
43
app/Models/WalletTransaction.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\WalletTransactionType;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WalletTransaction extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => WalletTransactionType::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function isTransfer(): Attribute
|
||||
{
|
||||
return Attribute::get(fn () => filled($this->transfer_id));
|
||||
}
|
||||
|
||||
public function transfer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WalletTransfer::class, 'transfer_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Wallet>
|
||||
*/
|
||||
public function wallet(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Wallet::class);
|
||||
}
|
||||
}
|
48
app/Models/WalletTransfer.php
Normal file
48
app/Models/WalletTransfer.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WalletTransfer extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Wallet>
|
||||
*/
|
||||
public function source(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Wallet::class, 'source_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Wallet>
|
||||
*/
|
||||
public function target(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Wallet::class, 'target_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<WalletTransaction>
|
||||
*/
|
||||
public function credit(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WalletTransaction::class, 'credit_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Wallet>
|
||||
*/
|
||||
public function debit(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WalletTransaction::class, 'debit_id');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user