/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create('pl_PL'); foreach (range(1, 5) as $index) { DB::table('pages')->insert(['name' => $faker->name, 'short_description' => $faker->realText(rand(20, 20)), 'description' => $faker->realText(rand(20, 20)), 'seo' => Illuminate\Support\Str::slug($faker->name), 'public_date' => date($format = 'Y-m-d'), 'create_date' => date($format = 'Y-m-d')]); } }
/** * Return an array of answers. * * @return array */ public function answersExplodedArray() { $groupped = []; foreach ($this->answers->allWithMedicalCenters()->toArray() as $answer) { foreach ($answer as $key => $value) { $answer_id = $answer['id']; // If we find a nested array, ignore it if (is_array($answer[$key])) { continue; } // When we are at medical_center_id, substitute it for its name and id if ($key === 'medical_center_id') { $groupped['medical_center_id'][$answer_id] = $answer['medical_center']['id']; $groupped['medical_center_email'][$answer_id] = $answer['medical_center']['email']; $groupped['medical_center'][$answer_id] = $answer['medical_center']['name']; continue; } // if (!is_array($value)) { // $values = (!in_array($key, $this->dontExplodeValue)) ? explode(',', $value) : [$value]; // } // Add it to the groupped array $group = array_filter(explode(',', $value)); if (!in_array($key, $this->dontExplodeValue)) { // if (count($group) > 1) { foreach ($group as $val) { // Ignore specific field if (in_array($key, ['commentaires'])) { continue; } $str = new \Illuminate\Support\Str(); $val = substr($str->slug($val), 0, 35); $groupped[$key . '_' . $val][$answer_id] = 1; } } else { $groupped[$key][$answer_id] = $value; } } } return $groupped; }
<?php /** * User Factory */ $factory->define(App\Models\User::class, function (Faker\Generator $faker) { return ['name' => $faker->name, 'email' => $faker->email, 'password' => bcrypt(str_random(10))]; }); $factory->defineAs(App\Models\User::class, 'activated', function (Faker\Generator $faker) use($factory) { $user = $factory->raw(App\Models\User::class); return array_merge($user, ['status' => UserStatus::ACTIVATED()]); }); $factory->defineAs(App\Models\User::class, 'deactivated', function (Faker\Generator $faker) use($factory) { $user = $factory->raw(App\Models\User::class); return array_merge($user, ['status' => UserStatus::DEACTIVATED()]); }); /** * Post Factory */ $factory->define(App\Models\Post::class, function (Faker\Generator $faker) { $sentence = $faker->sentence; return ['user_id' => 1, 'title' => $sentence, 'excerpt' => $sentence, 'body' => $faker->paragraphs(6, true), 'uri' => Illuminate\Support\Str::slug($sentence)]; }); $factory->defineAs(App\Models\Post::class, 'published', function (Faker\Generator $faker) use($factory) { $post = $factory->raw(App\Models\Post::class); return array_merge($post, ['status' => PostStatus::PUBLISHED()]); }); $factory->defineAs(App\Models\Post::class, 'drafted', function (Faker\Generator $faker) use($factory) { $post = $factory->raw(App\Models\Post::class); return array_merge($post, ['status' => PostStatus::DRAFTED()]); });