/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $data = $this->csv_to_array(base_path() . '/database/seeds/csv_files/faucets.csv');
     foreach ($data as $d) {
         $url = $d['url'];
         try {
             $meta = new WebsiteMeta($url);
             $faucet = new Faucet(['name' => $d['name'], 'url' => $url, 'interval_minutes' => (int) $d['interval_minutes'], 'min_payout' => (int) $d['min_payout'], 'max_payout' => (int) $d['max_payout'], 'has_ref_program' => $d['has_ref_program'], 'ref_payout_percent' => (int) $d['ref_payout_percent'], 'comments' => $d['comments'], 'is_paused' => $d['comments'], 'meta_title' => $meta->title(), 'meta_description' => $meta->description(), 'meta_keywords' => $meta->keywords(), 'has_low_balance' => false]);
             $faucet->save();
         } catch (Exception $e) {
             error_log($e->getMessage() . "<br>" . 'The URL "' . $url . '" does not exist or is experiencing technical issues.');
         }
     }
 }
 /**
  * Store a newly created faucet in storage.
  *
  * @return Response
  * @internal param Request $request
  */
 public function store()
 {
     //Create the validator to process input for validation.
     $validator = Validator::make(Input::except('send_tweet'), FaucetValidator::validationRulesNew());
     //If validator fails, return to the create page -
     //with input still in form, and accompanied with
     //the relevant errors.
     if ($validator->fails()) {
         return Redirect::to('/admin/faucets/create')->withErrors($validator)->withInput(Input::all());
     }
     //Declare and instantiate a new faucet.
     $faucet = new Faucet();
     //Assign input from the form to the faucet's properties -
     //except payment processors as this needs to be done separately.
     $faucet->fill(Input::except('faucet_payment_processors', 'send_tweet'));
     //Retrieve payment processor ids from multi-select dropdown
     $paymentProcessorIds = Input::get('faucet_payment_processors');
     //Save the faucet, with the filled-in data.
     $faucet->save();
     //Now we have saved a faucet, we can begin inserting associated
     //payment processors from input - in a many-many relationship.
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     foreach ($paymentProcessorIds as $paymentProcessorId) {
         $faucet->paymentProcessors()->attach((int) $paymentProcessorId);
     }
     //Associated the currently logged in user with the new faucet.
     $faucet->users()->attach(Auth::user()->id);
     // Re-enable foreign key checks after inserting
     //many-many records.
     DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     //Redirect to the faucet's page, with a success message.
     Session::flash('success_message', 'The faucet has successfully been created and stored!');
     if (Input::get('send_tweet') == 1) {
         $faucetUrl = url('/faucets/' . $faucet->slug);
         $user = User::find(Auth::user()->id);
         $twitter = new Twitter($user);
         $twitter->sendTweet("Hey everyone, just added another #Bitcoin faucet @ " . $faucetUrl . ". Check it out now! #FreeBTCWebsite");
     }
     return Redirect::to('/faucets/' . $faucet->slug);
 }