public static function customCreate(CreateConversationRequest $request) { $conv = new Conversation(); $conv->Title = $request->Title; // if nothing specified in the request if (!$request->has('user_id')) { // if we are not even logged ( happen while seeding base) if (!\Auth::check()) { $conv->user_id = User::first()->id; } else { $conv->user_id = \Auth::id(); } } // if Pending status is specified we take it, if not default value will be applied (false) if (!$request->has('Pending')) { $conv->Pending = $request->Pending; } $conv->created_at = Carbon::now(); $conv->save(); // When conversation is settled the Thread can be created $thread = new Thread(); $thread->user_id = $conv->user_id; $thread->Content = $request->Content; $thread->conversation_id = $conv->id; $thread->created_at = Carbon::now(); $thread->Pending = $conv->Pending; $thread->save(); return true; }
public function userReadDiscussion() { if (\Auth::check()) { return $this->hasMany('App\\UserReadDiscussion')->where('user_id', '=', \Auth::user()->id); } else { abort(500, 'Need to be logged in to access this userReadDiscussion relation'); } }
public function myWatchlist() { if (Auth::check() && Watchlist::where('user_id', Auth::user()->id)->where('art_id', $this->id)->exists()) { return true; } else { return false; } }
public static function tipoUserLogado() { if (!\Auth::check()) { return "*"; } $user = User::whereRaw('name=?', [\Auth::user()->name]); if ($user->count() == 1) { return $user->first()->tipo; } return ""; }
/** * @return string */ public static function getQotd() { if (Cache::has('qotd')) { $quote = Cache::get('qotd'); if (is_null($quote->speaker)) { return "<span class='text-lg'>“</span> {$quote->text} <span class='text-lg'>”</span>"; } else { return "<span class='text-lg'>“</span> {$quote->text} <span class='text-lg'>”</span><br> - {$quote->speaker}"; } } else { if (\Auth::check() && \Auth::user()->isAdmin()) { return "<span class='text-danger'><i>No Quote set as Quote of the Day and so a random quote will be shown to public.</i></span>"; } $quote = self::random(); if (is_null($quote->speaker)) { return "<span class='text-lg'>“</span> {$quote->text} <span class='text-lg'>”</span>"; } else { return "<span class='text-lg'>“</span> {$quote->text} <span class='text-lg'>”</span><br> - {$quote->speaker}"; } } }
public static function cantUpdate($id) { return \Auth::check() && (\Auth::id() == $id || \Auth::user() && in_array(\Auth::user()->role, ['admin', 'root'])); }
/** * @param Builder|\Illuminate\Database\Eloquent\Builder|Profile $query * @return mixed */ public function scopeVisible($query) { return $query->where(function ($query) { $query = $query->approved(); if (\Auth::check()) { $query = $query->orWhere('user_id', \Auth::id()); } return $query; }); }