/** * Store a secret. * * @param Request $request * @return Response */ public function storeSecret(Request $request) { $validator = Validator::make($request->all(), ['content' => 'required']); if ($validator->fails()) { session()->flash('flash_info', 'Validation error.'); } else { $secret = new Secret(); $secret->user_id = $request->user_id; $secret->content = $request->content; $secret->passcode = $request->passcode; $secret->url = $this->createUrlHash(); // $secret->expires_at = $request->expires_at; $secret->save(); session()->flash('flash_success', 'Secret created, url is: ' . $secret->url . '.'); } return redirect()->route('home'); }
/** * Display the specified resource. * * @param text $uuid4 * @return Response */ public function show($uuid4) { $secret = Secret::where('uuid4', crypt($uuid4, '$6$rounds=5000$' . getenv('APP_SALT') . '$'))->first(); if (!empty($secret)) { // Check for expiry if (Carbon::now()->gte($secret->expires_at) || $secret->count_views >= $secret->expires_views) { $secret->delete(); } else { // Increment the view count $secret->increment('count_views'); // Get attributes for display $secretDecrypted = Crypt::decrypt($secret->secret); $expires_at = $secret->expires_at; $views_remaining = $secret->expires_views - $secret->count_views; } } return view('secret.show', compact('secretDecrypted', 'expires_at', 'views_remaining')); }