2020-11-03 17:18:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Database\Factories;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
2023-08-28 00:13:40 -05:00
|
|
|
use Silber\Bouncer\BouncerFacade as Bouncer;
|
2020-11-03 17:18:31 +01:00
|
|
|
|
2023-08-28 00:13:40 -05:00
|
|
|
/** @extends Factory<\App\Models\User> */
|
2020-11-03 17:18:31 +01:00
|
|
|
class UserFactory extends Factory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2023-05-24 22:21:54 +02:00
|
|
|
public function definition(): array
|
2020-11-03 17:18:31 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
'auth_type' => 'mysql',
|
2022-09-01 19:31:25 +02:00
|
|
|
'username' => $this->faker->unique()->userName(),
|
|
|
|
'realname' => $this->faker->name(),
|
|
|
|
'email' => $this->faker->safeEmail(),
|
2021-10-18 03:01:07 -05:00
|
|
|
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
2020-11-03 17:18:31 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function admin()
|
|
|
|
{
|
2023-08-28 00:13:40 -05:00
|
|
|
return $this->afterCreating(function ($user) {
|
|
|
|
Bouncer::allow('admin')->everything();
|
|
|
|
$user->assign('admin');
|
2020-11-03 17:18:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function read()
|
|
|
|
{
|
2023-08-28 00:13:40 -05:00
|
|
|
return $this->afterCreating(function ($user) {
|
|
|
|
Bouncer::allow(Bouncer::role()->firstOrCreate(['name' => 'global-read'], ['title' => 'Global Read']))
|
|
|
|
->to('viewAny', '*', []);
|
|
|
|
$user->assign('global-read');
|
2020-11-03 17:18:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|