public function about() { if (Auth::isSubscriber()) { return redirect('/missioncontrol'); } return view('missionControl.about', ['stripePublicKey' => Config::get('services.stripe.public')]); }
public function incrementViewCounter() { // Only increment the view counter if the current user is a subscriber if (Auth::isSubscriber()) { $modelName = (new ReflectionClass($this))->getShortName(); $modelKey = strtolower($modelName) . '_id'; // Only increment the view counter if the user has not visited in 1 hour if (!Redis::exists($modelName . 'ViewByUser:'******':' . Auth::id())) { // Increment Redis::hincrby($modelName . ':' . $this->{$modelKey}, 'views', 1); // Add user to recent views Redis::setex($modelName . 'ViewByUser:'******':' . Auth::id(), 3600, true); } } }
public function favorite($object_id) { if (Auth::isSubscriber()) { // Create Favorite if (request()->isMethod('post')) { if (Auth::user()->favorites()->count() == 0) { Favorite::create(array('object_id' => $object_id, 'user_id' => Auth::id())); } // Delete Favorite } elseif (request()->isMethod('delete')) { Auth::user()->favorites()->where('object_id', $object_id)->firstOrFail()->delete(); } Redis::sadd('objects:toReindex', $object_id); return response()->json(null, 204); } return response()->json(false, 401); }
/** * GET (AJAX), /missions/{$slug}/telemetry. Fetches all mission telemetries for a specified mission, * ordered by the telemetry timestamp. * * @param $slug * @return \Illuminate\Http\JsonResponse */ public function telemetry($slug) { $telemetryQuery = Telemetry::whereHas('mission', function ($q) use($slug) { $q->whereSlug($slug); })->orderBy('timestamp', 'ASC'); if (Auth::isSubscriber()) { return response()->json($telemetryQuery->get()); } else { return response()->json($telemetryQuery->get(['telemetry_id', 'timestamp', 'readout'])); } }