public function newTweet(Request $request)
 {
     $this->validate($request, ['content' => 'required|max:140']);
     $newTweet = new Tweet();
     $newTweet->content = $request->content;
     $newTweet->user_id = \Auth::user()->id;
     $newTweet->save();
     //Process Tags
     $tags = explode('#', $request->tags);
     $tagsFormatted = [];
     //clean up the tags
     foreach ($tags as $tag) {
         if (trim($tag)) {
             $tagsFormatted[] = strtolower(trim($tag));
         }
     }
     //Loop over each tag
     foreach ($tagsFormatted as $tag) {
         //Grab the first matching result OR insert this new unique tag
         $theTag = Tag::firstOrCreate(['name' => $tag]);
         $allTagIds[] = $theTag->id;
     }
     //Attacth the Tag IDs to the tweet
     $newTweet->tags()->attach($allTagIds);
     return redirect('profile');
 }
 public function newTweet(Request $request)
 {
     $this->validate($request, ['content' => 'required|min:2|max:140']);
     $newTweet = new Tweet();
     // point to columns in db
     $newTweet->content = $request->content;
     // user who is logged in take their id
     $newTweet->user_id = \Auth::user()->id;
     // Save into database
     $newTweet->save();
     // Process the tags
     $tags = explode('#', $request->tags);
     $tagsFormatted = [];
     // clean up tags, remove white spaces
     foreach ($tags as $tag) {
         // if after trimming something remains
         if (trim($tag)) {
             $tagsFormatted[] = strtolower(trim($tag));
         }
     }
     $allTagIds = [];
     // Loop over eah tag
     foreach ($tagsFormatted as $tag) {
         // Grab the first matching result or insert this new unique tag
         // if tag is present will not insert into db. If not present, inserts into db.
         $theTag = Tag::firstOrCreate(['name' => $tag]);
         $allTagIds[] = $theTag->id;
     }
     // Attach the tag ids to the tweet
     $newTweet->tags()->attach($allTagIds);
     return redirect('profile');
 }
예제 #3
0
 public function create(Request $request)
 {
     $tweet = $request->input('tweet');
     $newTweet = new Tweet();
     $newTweet->tweet = $tweet;
     $newTweet->save();
 }
예제 #4
0
 public function update(Request $request, Tweet $tweet)
 {
     $tweet_data = $request->except(['_token']);
     $tweet->fill($tweet_data);
     $tweet->save();
     return redirect('/tweets');
 }
예제 #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $tweet = new Tweet();
     $tweet->title = $request->input("title");
     $tweet->body = $request->input("body");
     $tweet->save();
     return redirect()->route('tweets.index')->with('message', 'Item created successfully.');
 }
예제 #6
0
 public function store(Request $request)
 {
     $input_tweet = $request->input('tweet');
     $tweet = new Tweet();
     $tweet->tweet = $input_tweet;
     $tweet->user_id = Auth::user()->id;
     $tweet->save();
     return redirect('tweet');
 }
 public function newTweet(Request $request)
 {
     $this->validate($request, ['content' => 'required|min:4|max:140']);
     $newTweet = new Tweet();
     $newTweet->content = $request->content;
     $newTweet->user_id = \Auth::user()->id;
     $newTweet->save();
     return redirect('profile');
 }
예제 #8
0
 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required|unique:tweets|min:3|max:255', 'body' => 'required']);
     $image_name = $this->dealWithImage($request);
     $tweet = new Tweet();
     $tweet->title = $request->input("title");
     $tweet->body = $request->input("body");
     $tweet->user_id = auth()->guest() ? 0 : 1;
     $tweet->image_name = $image_name;
     $tweet->save();
     return redirect()->route('tweets.index')->with('message', 'Item created successfully.');
 }
예제 #9
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     \Log::info('Fetch tweets');
     $client = new Client('https://api.twitter.com/1.1/');
     $auth = new Oauth(['consumer_key' => env('TWITTER_CONSUMER_KEY'), 'consumer_secret' => env('TWITTER_CONSUMER_SECRET'), 'token' => env('TWITTER_ACCESS_TOKEN'), 'token_secret' => env('TWITTER_ACCESS_TOKEN_SECRET')]);
     $client->addSubscriber($auth);
     //$response = $client->get('search/tweets.json?q=%23peukpoll&since=' . date('Y-m-d'))->send();
     $response = $client->get('search/tweets.json?q=%23peukpoll')->send();
     $data = $response->json()['statuses'];
     $tweets = array_fetch($response->json()['statuses'], 'text');
     foreach ($tweets as $tweet) {
         $values[] = explode(' ', $tweet);
     }
     for ($i = 0; $i < count($values); $i++) {
         $user = User::where('username', $data[$i]['user']['screen_name'])->first();
         if ($user == null) {
             $user = new User();
             $user->username = $data[$i]['user']['screen_name'];
             $user->save();
         }
         $tweet = Tweet::where('tweet', $data[$i]['id'])->first();
         if ($tweet == null) {
             $tweet = new Tweet();
             $tweet->x = $values[$i][0];
             $tweet->y = $values[$i][2];
             $tweet->score_x = 1;
             $tweet->score_y = 1;
             $tweet->tweet = $data[$i]['id'];
             $tweet->user()->associate($user);
             $tweet->save();
             $numberOfUpcomingTweets = UpcomingTweet::all()->count();
             if ($numberOfUpcomingTweets > 0) {
                 $upcomingTweet = new UpcomingTweet();
                 $upcomingTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 year'));
                 $upcomingTweet->tweet()->associate($tweet);
                 $upcomingTweet->save();
             } else {
                 $upcomingTweet = new UpcomingTweet();
                 $upcomingTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 hour'));
                 $upcomingTweet->tweet()->associate($tweet);
                 $upcomingTweet->save();
             }
         }
     }
 }
예제 #10
0
 public function repost($tweet_id, $user_id)
 {
     $post = Tweet::find($tweet_id);
     $repost = new Tweet();
     $repost->tweet_id = $tweet_id;
     $repost->tweet = $post->tweet;
     $repost->user_id = $user_id;
     $repost->original_tweet_id = 0;
     $repost->save();
     $notification = new RepostNotification();
     $notification->user_id = Auth::user()->id;
     $notification->my_user_id = Tweet::find($tweet_id)->user->id;
     $notification->tweet_id = $tweet_id;
     $notification->reply_id = 0;
     $notification->type = "Repost";
     $notification->save();
     return redirect('/' . Auth::user()->username);
 }
 public function newTweet(Request $request)
 {
     $this->validate($request, ['content' => 'required|max:140']);
     $newTweet = new Tweet();
     $newTweet->content = $request->content;
     $newTweet->user_id = \Auth::user()->id;
     $newTweet->save();
     $tags = explode(' ', $request->tags);
     $tagsFormatted = [];
     foreach ($tags as $tag) {
         //clean up newly created tags array.
         if (trim($tag)) {
             $tagsFormatted[] = strtolower(trim($tag));
         }
     }
     //loop over each tag
     foreach ($tagsFormatted as $tag) {
         //loop over each formatted tag and grab the first matching result or add new tag to db
         $theTag = Tag::firstOrCreate(['name' => $tag]);
         $allTagIds[] = $theTag->id;
     }
     $newTweet->tags()->attach($allTagIds);
     return redirect('profile');
 }
예제 #12
0
 public function postNewTweet(Request $request)
 {
     $tweet = new Tweet();
     $tweet->x = $request->x;
     $tweet->y = $request->y;
     $tweet->score_x = 1;
     $tweet->score_y = 1;
     $tweet->user()->associate(User::find(1));
     $tweet->save();
     if ($request->first) {
         $oldTweet = UpcomingTweet::orderBy('id', 'asc')->first();
         $oldTweet->delete();
         $newTweet = new UpcomingTweet();
         $newTweet->id = 1;
         $newTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 hour'));
         $newTweet->tweet()->associate($tweet);
         $newTweet->save();
     } else {
         $newTweet = new UpcomingTweet();
         $newTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 year'));
         $newTweet->tweet()->associate($tweet);
         $newTweet->save();
     }
     return redirect()->route('admin');
 }