Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/43 incidents seed #44

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function run()
$this->call(CountiesTableSeeder::class);
$this->call(CitiesTableSeeder::class);
$this->call(IncidentTypesTableSeeder::class);
//$this->call(IncidentsTableSeeder::class);
$this->call(IncidentsTableSeeder::class);
$this->call(UsersTableSeeder::class);
$this->call(PrecinctsTableSeeder::class);
}
Expand Down
63 changes: 35 additions & 28 deletions database/seeds/IncidentTypesTableSeeder.php
Original file line number Diff line number Diff line change
@@ -1,76 +1,83 @@
<?php

use Illuminate\Database\Seeder;
use App\IncidentType;

class IncidentTypesTableSeeder extends Seeder
{

/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
IncidentType::create([
public $incidentTypes = [
[
'id' => 1,
'label' => 'IT_OTHER',
'code' => 'OTH',
'name' => 'Altul'
]);
IncidentType::create([
],
[
'id' => 2,
'label' => 'IT_OBSERVERS',
'code' => 'ELE',
'name' => 'Probleme legate de campania electorală'
]);
IncidentType::create([
],
[
'id' => 3,
'label' => 'IT_MEDIA',
'code' => 'MED',
'name' => 'Discurs instigator la ură'
]);
IncidentType::create([
],
[
'id' => 4,
'label' => 'IT_BRIBE',
'code' => 'MIT',
'name' => 'Vot multiplu/Mită electorală'
]);
IncidentType::create([
],
[
'id' => 5,
'label' => 'BUILDING',
'code' => 'NBE',
'name' => 'Nereguli legate de funcționarea administrației electorale'
]);
IncidentType::create([
],
[
'id' => 7,
'label' => 'LOCATION',
'code' => 'OBP',
'name' => 'Vot în străinătate'
]);
IncidentType::create([
],
[
'id' => 8,
'label' => 'IT_ELEC_TURISM',
'code' => 'TEL',
'name' => 'Transport organizat de alegători'
]);
IncidentType::create([
],
[
'id' => 9,
'label' => 'IT_PUBLIC_FOUNDS',
'code' => 'FEL',
'name' => 'Abuz de resurse publice'
]);
IncidentType::create([
],
[
'id' => 11,
'label' => 'POLICE',
'code' => 'OPN',
'name' => 'Presiuni din partea autorităților locale'
]);
IncidentType::create([
],
[
'id' => 12,
'label' => 'VOTE',
'code' => 'NUM',
'name' => 'Probleme în zilele votului'
]);
]
];

/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
foreach ($this->incidentTypes as $incidentType) {
IncidentType::create($incidentType);
}
}

}
16 changes: 13 additions & 3 deletions database/seeds/IncidentsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,30 @@ public function run()
{

$faker = Faker::create();
$incidentTypeIds = $this->getIncidentIds();

foreach (range(1, 141) as $index)
{
foreach (range(1, 141) as $index) {
Incident::create([
'first_name' => $faker->firstName(),
'last_name' => $faker->lastName(),
'county_id' => $faker->numberBetween(1, 42),
'city_id' => $faker->numberBetween(1, 3000),
'precinct_id' => $faker->numberBetween(1, 90000),
'incident_type_id' => $faker->numberBetween(1, 10),
'incident_type_id' => $incidentTypeIds[array_rand($incidentTypeIds)],
'description' => $faker->realText(250),
'image_url' => $faker->imageUrl(320, 240, 'cats'),
'status' => $faker->randomElement(['Approved', 'Pending', 'Rejected'])
]);
}
}

/**
* @return array
*/
private function getIncidentIds()
{
return array_map(function ($incidentType) {
return $incidentType['id'];
}, (new IncidentTypesTableSeeder())->incidentTypes);
}
}