AdminPermissionFactory.php 812 B

1234567891011121314151617181920212223242526
  1. <?php
  2. /* @var $factory \Illuminate\Database\Eloquent\Factory */
  3. use App\Models\AdminPermission;
  4. use Faker\Generator as Faker;
  5. $factory->define(AdminPermission::class, function (Faker $faker) {
  6. $getMethods = function () use ($faker) {
  7. return $faker->randomElements(AdminPermission::$httpMethods, $faker->numberBetween(0, 3));
  8. };
  9. $httpPaths = [];
  10. for ($i = 0; $i <= $faker->numberBetween(1, 3); $i++) {
  11. $specifyMethod = (mt_rand(0, 10) > 8) ? implode(',', $getMethods()).':' : '';
  12. $httpPaths[] = $specifyMethod.'/'.fake_path();
  13. }
  14. $httpPaths = implode("\n", $httpPaths);
  15. return [
  16. 'name' => 'perm_'.$faker->unique()->word,
  17. 'slug' => $faker->unique()->word,
  18. 'http_method' => $getMethods(),
  19. 'http_path' => $httpPaths,
  20. ];
  21. });