public function update(Request $request, Tweet $tweet) { $tweet_data = $request->except(['_token']); $tweet->fill($tweet_data); $tweet->save(); return redirect('/tweets'); }
public function destroy(Tweet $tweet) { try { $tweet->delete(); return response()->json(['errors' => 'false', 'message' => 'The project has been deleted!']); } catch (\Exception $e) { return response()->json(['errors' => 'true', 'message' => 'Something went wrong!']); } }
public function index() { $analytics = new Analytics(); $optimalTweetTime = $analytics->optimalTweetTime(); $tweets = Tweet::all(); return view('tweets.index', ['tweets' => $tweets, 'time' => $optimalTweetTime]); }
/** * Show the application welcome screen to the user. * * @param MapReduce $mapReduce * @return Response */ public function index(MapReduce $mapReduce) { $total_tweets = Tweet::count(); $total_hashtag = Hashtag::count(); $agg_hashtags = $mapReduce->agg_hashtags(); return view('home')->with(['total_tweets' => $total_tweets, 'total_hashtag' => $total_hashtag, 'agg_hashtags' => $agg_hashtags]); }
public function update(Request $request) { $tweet = Tweet::find($request->input('tweet_id')); $tweet->tweet = $request->input('tweet'); $tweet->save(); return redirect('tweet'); }
public function edit(Request $request) { $id = $request->input('id'); $editedtweet = $request->input('tweet'); $spec = Tweet::find($id); $spec->tweet = $editedtweet; $spec->save(); }
/** * 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(); } } } }
public function findOrCreateByText($tweet) { $text = $tweet->text; if (!count(Tweet::where('text', $text)->get())) { return Tweet::create(['text' => $text, 'link' => $this->tweetHasLink($text), 'retweet_count' => $tweet->retweet_count, 'time' => $this->setTime($tweet->created_at), 'hour' => $this->findHour($tweet->created_at), 'favorite_count' => $tweet->favorite_count, 'hashtag_count' => count($tweet->entities->hashtags), 'retweet' => $this->tweetIsRT($text)]); } else { return Tweet::where('text', $text)->get(); } }
public function gestionesRealizadasExport(Request $request) { Excel::create('Gestiones Realizadas', function ($excel) { $excel->sheet('Gestiones', function ($sheet) { $tweets = Tweet::all(); $sheet->fromArray($tweets, null, 'A1', false, false); }); })->export('csv'); }
public function destroyTweet($id) { $tweet = Tweet::findOrFail($id); if ($tweet->user_id != \Auth::user()->id) { return 'Not your tweet'; } $tweet->delete(); return redirect('profile/' . $tweet->user->username); }
public function test() { $games = new GiantBombApi(); $gamesArray = $games->getAllGameInfoById(46090); $tweetV = \App\Tweet::getStatusVlambeer(); $tweetR = \App\Tweet::getStatusRami(); $tweetJ = \App\Tweet::getStatusJan(); return view('pages.giantbomb_api', compact('gamesArray', 'tweetV', 'tweetR', 'tweetJ')); }
public function submit(Request $request) { // Validate the input $this->validate($request, ['tweet' => ['required', 'min:10', 'max:140', 'unique:tweets,tweet']]); // Create and store the Tweet model Tweet::create($request->only('tweet')); // Flash a success message session()->flash('success', 'Tweet proposed!'); return redirect('/'); }
public function getLengthOfTweets() { $tweets = Tweet::all(); $tweet_lengths = []; foreach ($tweets as $tweet) { $len = strlen($tweet->getAttribute('text')); array_push($tweet_lengths, $len); } return $tweet_lengths; }
public function destroyTweet($id) { // Find the tweet $tweet = Tweet::findOrFail($id); // Check that the logged in user owns this tweet if ($tweet->user_id != \Auth::user()->id) { return 'Not your tweet'; } $tweet->delete(); return redirect('profile/' . $tweet->user->username); }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { $router->bind('messages', function ($id) { return \App\Messages::findOrFail($id); }); $router->bind('tweets', function ($id) { return \App\Tweet::findOrFail($id); }); $router->bind('users', function ($id) { return \App\User::findOrFail($id); }); parent::boot($router); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(LikeRequest $request) { $input = $request->all(); $like = new Like($input); $like->save(); $notification = new RepostNotification(); $notification->user_id = Auth::user()->id; $notification->my_user_id = Tweet::find($like->tweet_id)->user->id; $notification->tweet_id = $like->tweet_id; $notification->type = "Like"; $notification->reply_id = 0; $notification->save(); return redirect()->back(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { $search = ''; if ($search = $request->input('search')) { $tweets = Tweet::where('title', "LIKE", "%" . $search . "%")->orWhere('body', "LIKE", "%" . $search . "%")->paginate(10); } else { $tweets = Tweet::simplePaginate(5); //Tweet::all() } $users = User::all(); $tags = ['foo', 'bar']; $latests = Tweet::take(5)->get(); return view('home', compact('tweets', 'search', 'users', 'tags', 'latests')); }
public function send_to_queue($data) { if (isset($data['text']) && $data['text'] != null) { if (isset($data['user']['screen_name']) && $data['user']['screen_name'] != null) { $arr['text'] = $data['text']; $arr['user'] = $data['user']['screen_name']; Tweet::create($arr); if (!empty($data['entities']['hashtags'])) { foreach ($data['entities']['hashtags'] as $hashtag) { Hashtag::create(['hashtag' => $hashtag]); } } } } }
public function search() { $search = Input::get('search'); $country_id = Input::get('country_id'); $users = null; $tweets = null; if ($search != "") { $users = User::where('username', 'like', '%' . $search . '%')->where('country_id', $country_id)->get(); $tweets = Tweet::where('tweet', 'like', '%' . $search . '%')->where('country_id', $country_id)->get(); } else { $users = User::where('country_id', $country_id)->get(); $tweets = Tweet::where('country_id', $country_id)->get(); } return view('search_results', compact('users', 'tweets')); }
public static function searchLocationTweets($locName, $locLat, $locLng) { $location = Location::where('latitude', '=', round($locLat, 7))->where('longitude', '=', round($locLng, 7))->first(); $tweets = null; if ($location == null) { $location = new Location(); $location->name = $locName; $location->latitude = round($locLat, 7); $location->longitude = round($locLng, 7); $locRet = $location->save(); //save search history $search = new Search(); $search->location_id = $location->id; $search->user = $_COOKIE['user']; $search->save(); $tweets = self::getTweets($locName, round($locLat, 7), round($locLng, 7)); //save tweets foreach ($tweets as $tweet) { $tweet->search_id = $search->id; $tweet->save(); } } else { $search = Search::where('location_id', '=', $location->id)->orderBy('created_at', 'desc')->first(); $searchTime = strtotime($search->created_at); //save new search $newSearch = new Search(); $newSearch->location_id = $location->id; $newSearch->user = $_COOKIE['user']; $newSearch->save(); //if search is older than 1 hour, tweet again if ($searchTime <= strtotime('-' . Config::get('app.cache_duration') . ' minutes')) { $tweets = self::getTweets($locName, round($locLat, 7), round($locLng, 7)); //save tweets foreach ($tweets as $tweet) { $tweet->search_id = $search->id; $tweet->save(); } } else { //get last search with tweets $search = DB::table('searches')->where('location_id', '=', $location->id)->whereExists(function ($query) { $query->select(DB::raw(1))->from('tweets')->whereRaw('tweets.search_id = searches.id'); })->orderBy('created_at', 'desc')->first(); $tweets = Tweet::where('search_id', '=', $search->id)->get(); } } return $tweets; }
public function deleteTweet(Request $request) { $responseData = array(); $tweet = Tweet::find($request->input('id')); if ($tweet->user_id == $request->user()->id) { if ($tweet->delete()) { $responseData['status'] = true; $responseData['message'] = "success"; } else { $responseData['status'] = false; $responseData['message'] = "not success"; } } else { $responseData['status'] = false; $responseData['message'] = "not success"; } return response()->json($responseData); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $tweet = Tweet::findOrFail($id); $tweet->delete(); return redirect()->route('tweets.index')->with('message', 'Item deleted successfully.'); }
public function repost_number() { return Tweet::where('tweet_id', $this->id)->count(); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $tweet = Tweet::find($id); $user = User::find($tweet->user_id); return view('tweets.show', compact('tweet', 'user')); }
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'); }
public function tweets($pagination = 100) { return Tweet::select('tweets.user_id', 'users.name', 'users.username', 'tweets.message', 'tweets.created_at', 'tweets.updated_at')->join('users', 'tweets.user_id', '=', 'users.id')->where('user_id', $this->id)->orderBy('created_at', 'desc')->paginate($pagination); }
/** * Show the application welcome screen to the user. * * @param MapReduce $mapReduce * @return Response */ public function twitterTotal() { $count = Tweet::count(); return $this->response->withItem($count, new CountTransformer()); }