/**
  * Handle Allowed Sender
  *
  * @param Integer $id
  * @return Response
  */
 public function ban($id)
 {
     $sender = Senders::findOrFail($id);
     $sender->flagged = 0;
     $sender->banned = 1;
     $sender->save();
     return redirect()->back()->with(['status' => 'success', 'message' => 'Sender banned.']);
 }
 /**
  * Register custom Blade composers
  *
  * @return void
  */
 private function bladeComposers()
 {
     /**
      * Master.Private
      */
     view()->composer('master.private', function ($view) {
         /**
          * Provide counts of all Records
          */
         $counts = array();
         $counts['senders'] = Senders::all()->count();
         $counts['targets'] = Targets::all()->count();
         $counts['queue'] = Tweets::inQueue()->count();
         $counts['sent'] = Tweets::areSent()->count();
         $counts['failed'] = Tweets::haveFailed()->count();
         $counts['flagged'] = Tweets::isFlagged()->count();
         $view->with('counts', $counts);
     });
 }
 /**
  * Return the Senders page
  *
  * @return View
  */
 public function getSenders()
 {
     $senders = Senders::all();
     return view('private.senders')->with('senders', $senders);
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     // Check if IP is banned
     $banned = Senders::where('ip', $this->ip())->where('banned', 1)->exists();
     return !$banned;
 }
 /**
  * Add Tweet to Queue
  *
  * @param Array $data
  * @return Response
  */
 private function queue($input)
 {
     $data = array();
     /**
      * Remove `tweet_` prefix
      */
     foreach ($input as $key => $value) {
         if (strpos($key, 'tweet_') === 0) {
             $key = substr($key, 6);
         }
         $data[$key] = $value;
     }
     /**
      * If Sender or Target flagged, flag Tweet
      */
     if (Senders::findOrFail($data['sender'])->flagged || Targets::findOrFail($data['target'])->watched) {
         $data['flagged'] = 1;
     }
     Tweets::create($data);
     /**
      * If Tweet Flagged, return Warning
      */
     if ($data['flagged']) {
         return response()->json(['code' => 406, 'status' => 'flagged', 'message' => 'Tweet was flagged for moderation.']);
     }
     return response()->json(['code' => 200, 'status' => 'success', 'message' => 'Tweet added to the queue.']);
 }