/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = User::where('is_admin', '=', true)->firstOrFail();
     $twitter = new Twitter($user);
     if ($twitter != null) {
         $twitter->sendRandomFaucetTweet();
     }
 }
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     $schedule->command('inspire')->hourly();
     // Check the statuses of each faucet every hour.
     $schedule->call(function () {
         Faucets::checkUpdateStatuses();
     })->hourly()->environments('production');
     // Schedule a random tweet of a selected faucet every hour.
     $schedule->call(function () {
         $user = User::where('is_admin', '=', true)->firstOrFail();
         $twitter = new Twitter($user);
         $twitter->sendRandomFaucetTweet();
     })->hourly()->environments('production');
 }
 /**
  * Update the specified faucet in storage.
  *
  * @param $slug
  * @return Response
  * @internal param int $id
  */
 public function update($slug)
 {
     //Retrieve faucet to be updated.
     $faucet = Faucet::findBySlugOrId($slug);
     $id = $faucet->id;
     //Pass input into the validator -
     //with current faucet id, so
     //'not unique' errors won't be displayed
     //when updating.
     $validator = Validator::make(Input::except('send_tweet'), FaucetValidator::validationRulesEdit($id));
     //If validation fails, redirect back to the
     //editing page - with input and relevant errors.
     if ($validator->fails()) {
         return Redirect::to('/admin/faucets/' . $slug . '/edit')->withErrors($validator)->withInput(Input::all());
     }
     //Get all input from edit/update request,
     //then populate the faucet with the given
     //data.
     $faucet->fill(Input::except('send_tweet'));
     //Retrieve payment processor ids from update.
     $paymentProcessorIds = Input::get('faucet_payment_processors');
     //Below logic disables foreign key checking before
     //updating many-to-many table (faucet_payment_processor)
     //that ties instances of faucets to instances of payment
     //processors. The retrieved payment processor ids are
     //iterated through, then synced with the current faucet in
     // the many-many table. Then foreign key checking is re-enabled.
     DB::statement('SET FOREIGN_KEY_CHECKS = 0');
     $faucet->paymentProcessors()->detach();
     foreach ($paymentProcessorIds as $paymentProcessorId) {
         $faucet->paymentProcessors()->attach((int) $paymentProcessorId);
     }
     DB::statement('SET FOREIGN_KEY_CHECKS = 1');
     //Save the changes made to the faucet.
     $faucet->save();
     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 updated #Bitcoin faucet (" . $faucet->name . ") @ " . $faucetUrl . " #FreeBTCWebsite");
     }
     Session::flash('success_message', 'The faucet has successfully been updated!');
     //Redirect to the faucet's page
     return Redirect::to('/faucets/' . $slug);
 }