63 lines
1.2 KiB
PHP
Raw Normal View History

2020-01-13 11:24:59 +03:00
<?php
2020-10-14 17:07:59 +03:00
namespace Database\Factories;
use App\Abstracts\Factory;
2020-01-13 11:24:59 +03:00
use App\Models\Auth\Permission;
2020-10-14 17:07:59 +03:00
use App\Models\Auth\Role as Model;
class Role extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$name = $this->faker->word;
return [
'name' => strtolower($name),
'display_name' => $name,
'description' => $name,
];
}
/**
* Indicate the model permissions.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function permissions()
{
2020-10-15 00:08:41 +03:00
return $this->state([
'permissions' => $this->getPermissions(),
]);
2020-10-14 17:07:59 +03:00
}
/**
* Configure the model factory.
*
* @return $this
*/
public function configure()
{
return $this->afterCreating(function (Model $role) {
$role->permissions()->attach($this->getPermissions());
});
}
2020-10-15 00:08:41 +03:00
protected function getPermissions()
{
return Permission::take(50)->pluck('id')->toArray();
}
2020-10-14 17:07:59 +03:00
}