/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $month = new Carbon($this->argument('month'));
     $billboards = Billboard::activated()->get();
     $pictures = Storage::files();
     $missing_pictures = new Collection();
     foreach ($billboards as $billboard) {
         $facings = $billboard->facings->all();
         foreach ($facings as $facing) {
             $ref = $this->reference($billboard, $facing, $month);
             $image_url = "{$ref}.jpg";
             if (in_array($image_url, $pictures)) {
                 try {
                     $this->trackingRepository->create(['facing_id' => $facing->id, 'image_url' => $image_url, 'tracking_date' => $month, 'location_id' => $billboard->location_id]);
                     $this->info('Tracking #' . $ref . ' with image url ' . $image_url . ' created successfully.');
                 } catch (\Illuminate\Database\QueryException $e) {
                     $this->error('Tracking #' . $ref . ' already exists.');
                 }
             } else {
                 $this->error('Facing #' . $ref . ' picture missing.');
                 $missing_pictures->push(["name" => $facing->name, "image_url" => $image_url]);
             }
         }
     }
     if (!$missing_pictures->isEmpty()) {
         $this->notifyMissingPictures($missing_pictures, "*****@*****.**");
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('billboards')->truncate();
     $faker = Faker::create();
     foreach (range(1, 20) as $index) {
         Billboard::create(['latLng' => $faker->latitude . ", " . $faker->longitude, 'structure' => 'Attached to structure', 'placement' => 'Ground Level', 'size' => '5*15', 'panel_type' => 'Digital', 'road_type' => 'Highway', 'speed_of_road' => 120, 'billboard_owner_id' => BillboardOwner::first()->id]);
     }
 }
 public function run()
 {
     DB::table('facings')->truncate();
     $faker = Faker::create();
     foreach (range(1, 20) as $index) {
         Facing::create(['name' => Str::upper($faker->randomLetter), 'angle' => '5-25', 'is_obstructed' => $faker->boolean(50), 'contact_time' => '5-25', 'illumination_type' => '5-25', 'distance_from_road' => '5-25', 'billboard_proximity' => '50-100', 'billboard_id' => Billboard::find($faker->numberBetween(1, 20))->id]);
     }
 }
 /**
  * Show the form for editing the specified Facing.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function edit($id)
 {
     $facing = $this->facingRepository->findWithoutFail($id);
     $billboards = Billboard::lists('id', 'id');
     if (empty($facing)) {
         Flash::error('Facing not found');
         return redirect(route('facings.index'));
     }
     return view('facings.edit')->with('facing', $facing)->with('billboards', $billboards);
 }