generated from liutk/owl-admin-base
添加填充
parent
abd0ae0029
commit
5a80f9cd06
|
|
@ -43,4 +43,8 @@ class User extends Authenticatable
|
||||||
{
|
{
|
||||||
return $this->hasMany(UserGift::class, 'user_id');
|
return $this->hasMany(UserGift::class, 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function activityLogs(){
|
||||||
|
return $this->hasMany(UserActivity::class, 'user_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||||
|
*/
|
||||||
|
class UserActivityFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The current password being used by the factory.
|
||||||
|
*/
|
||||||
|
protected static ?string $password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'activity_id' => 1,
|
||||||
|
'mark' => rand(50, 500),
|
||||||
|
'join_times' => rand(5, 10),
|
||||||
|
'right_times' => rand(0, 5),
|
||||||
|
'last_join_at' => now(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -24,21 +24,9 @@ class UserFactory extends Factory
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => fake()->name(),
|
'nick_name' => fake()->name(),
|
||||||
'email' => fake()->unique()->safeEmail(),
|
'mini_openid' => Str::random(16),
|
||||||
'email_verified_at' => now(),
|
'avatar' => env('APP_URL').'/default-avatar.png',
|
||||||
'password' => static::$password ??= Hash::make('password'),
|
|
||||||
'remember_token' => Str::random(10),
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Indicate that the model's email address should be unverified.
|
|
||||||
*/
|
|
||||||
public function unverified(): static
|
|
||||||
{
|
|
||||||
return $this->state(fn (array $attributes) => [
|
|
||||||
'email_verified_at' => null,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Models\UserActivity;
|
||||||
|
|
||||||
|
class UserFactorySeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Seed the application's database.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
User::factory()->has(UserActivity::factory()->count(1), 'activityLogs')->count(40)->create();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue