/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('contractors')->truncate();
     $faker = Faker\Factory::create();
     for ($count = 0; $count < 100; $count++) {
         $contractor = new Contractors();
         $contractor->name = $faker->company;
         $contractor->address = $faker->streetAddress;
         $contractor->county = $faker->cityPrefix;
         $contractor->city = $faker->city;
         $contractor->state = $faker->stateAbbr;
         $contractor->zip = $faker->postcode;
         $contractor->fax = $faker->phoneNumber;
         $contractor->phone = $faker->phoneNumber;
         $contractor->email = $faker->email;
         $contractor->business_type = $faker->randomElement(['Single Entity', 'Branch Office']);
         $contractor->owner_firstname = $faker->firstName;
         $contractor->owner_lastname = $faker->lastName;
         $contractor->website = $faker->domainName;
         $contractor->ubi = $faker->randomNumber;
         $contractor->save();
         $agreement_id = $faker->numberBetween(1, 12);
         $jurisdiction = Jurisdictions::find($faker->numberBetween(1, 10));
         $contractor->agreements()->attach($agreement_id, ['jurisdiction_id' => $jurisdiction->id, 'jurisdiction' => $jurisdiction->jurisdiction, 'active' => 1]);
         $contractor->certifications()->attach([$faker->numberBetween(1, 8), $faker->numberBetween(1, 8), $faker->numberBetween(1, 8)]);
         $contractor->classifications()->attach([$faker->numberBetween(1, 11), $faker->numberBetween(1, 11)]);
         $contractor->scopes()->attach([$faker->numberBetween(1, 10), $faker->numberBetween(1, 10), $faker->numberBetween(1, 10)]);
     }
 }
 /**
  * Search conrtractors
  *
  * @param Request $request
  * @return Response
  */
 public function search(Request $request)
 {
     $scopesText = array_map(function ($v) {
         return array_get($v, 'scope', '');
     }, Scopes::whereIn('id', $request->get('scopes', []))->get(['scope'])->toArray());
     $classificationsText = array_map(function ($v) {
         return array_get($v, 'classification', '');
     }, Classifications::whereIn('id', $request->get('classifications', []))->get(['classification'])->toArray());
     $jurisdictionsText = array_map(function ($v) {
         return array_get($v, 'jurisdiction', '');
     }, Jurisdictions::whereIn('id', $request->get('jurisdictions', []))->get(['jurisdiction'])->toArray());
     $input = ['name' => $request->get('name', ''), 'phone' => preg_replace('/[()-.\\s]/', '', $request->get('phone', '')), 'scopes' => $request->get('scopes', []), 'scopesText' => $scopesText, 'classifications' => $request->get('classifications', []), 'classificationsText' => $classificationsText, 'jurisdictions' => $request->get('jurisdictions', []), 'jurisdictionsText' => $jurisdictionsText];
     $request->session()->put('input', $input);
     return redirect()->route('contractor.search.result');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('jurisdictions')->truncate();
     Jurisdictions::insert([['id' => 1, 'jurisdiction' => 'Sole International (INTL)'], ['id' => 2, 'jurisdiction' => 'Region Wide (RW)'], ['id' => 3, 'jurisdiction' => 'Western Washington (WWA)'], ['id' => 4, 'jurisdiction' => 'Eastern Washington (EWA/IDNO)'], ['id' => 5, 'jurisdiction' => 'Central Washington (CWA)'], ['id' => 6, 'jurisdiction' => 'Oregon (OR/SWWA)'], ['id' => 7, 'jurisdiction' => 'Montana (MT)'], ['id' => 8, 'jurisdiction' => 'Wyoming (WY)'], ['id' => 9, 'jurisdiction' => 'Southern Idaho (IDSO)'], ['id' => 10, 'jurisdiction' => 'Alaska (AK)']]);
 }