Initial commit
This commit is contained in:
26
database/factories/UserFactory.php
Normal file
26
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
protected static string $password = 'password';
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'password' => Hash::make(static::$password),
|
||||
];
|
||||
}
|
||||
}
|
44
database/factories/WalletFactory.php
Normal file
44
database/factories/WalletFactory.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Wallet;
|
||||
use App\Models\WalletTransaction;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Wallet>
|
||||
*/
|
||||
class WalletFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'balance' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
public function balance(int $balance): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'balance' => $balance,
|
||||
]);
|
||||
}
|
||||
|
||||
public function richChillGuy(): static
|
||||
{
|
||||
return $this
|
||||
->state(fn (array $attributes) => [
|
||||
'balance' => 1_000_000,
|
||||
])
|
||||
->has(
|
||||
WalletTransaction::factory()
|
||||
->amount(1_000_000)
|
||||
->credit()
|
||||
->reason('Just a rich chill guy'),
|
||||
'transactions'
|
||||
);
|
||||
}
|
||||
}
|
59
database/factories/WalletTransactionFactory.php
Normal file
59
database/factories/WalletTransactionFactory.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\WalletTransactionType;
|
||||
use App\Models\WalletTransaction;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<WalletTransaction>
|
||||
*/
|
||||
class WalletTransactionFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'amount' => fake()->numberBetween(1, 100),
|
||||
'type' => fake()->randomElement([
|
||||
WalletTransactionType::DEBIT,
|
||||
WalletTransactionType::CREDIT,
|
||||
]),
|
||||
'reason' => fake()->sentence(),
|
||||
];
|
||||
}
|
||||
|
||||
public function credit(): self
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'type' => WalletTransactionType::CREDIT,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function debit(): self
|
||||
{
|
||||
return $this->state(function (array $attributes) {
|
||||
return [
|
||||
'type' => WalletTransactionType::DEBIT,
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
public function amount(int $amount): self
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'amount' => $amount,
|
||||
]);
|
||||
}
|
||||
|
||||
public function reason(string $reason): self
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'reason' => $reason,
|
||||
]);
|
||||
}
|
||||
}
|
28
database/factories/WalletTransferFactory.php
Normal file
28
database/factories/WalletTransferFactory.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\WalletTransfer;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<WalletTransfer>
|
||||
*/
|
||||
class WalletTransferFactory extends Factory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'amount' => fake()->numberBetween(1, 100),
|
||||
];
|
||||
}
|
||||
|
||||
public function amount(int $amount): self
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'amount' => $amount,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user