/** * Execute the console command. * * @return mixed */ public function handle() { \Log::alert('Refresh tweets'); $tweet = UpcomingTweet::where('end', '<', date('Y-m-d H:i:s'))->first(); if ($tweet != null) { $tweet->delete(); $newTweet = UpcomingTweet::orderBy('id', 'asc')->first(); $newTweet->end = date('Y-m-d H:i:s', strtotime('+ 1 hour')); $newTweet->save(); } }
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'); }