public function create($request) { $validate = $this->validate($request, $this->rules); if ($validate->errors() == 0) { $user = Auth::get(); if ($user) { $post = new Post($request); $post->user_id = Auth::getUserId(); $post->text = nl2br($post->text); $post->update(); foreach ($user->followers() as $follower) { $notification = new Notification(); $notification->text = 'Používateľ ' . $user->nick . ' pridal nový príspevok s nadpisom ' . $post->title . '!'; $notification->user_id = $follower->id; $notification->link = 'prispevok/' . $post->id; $notification->save(); } return json_encode(['success' => 'Hejt bol úspešne pridaný!']); } } else { return json_encode(['errors' => $validate->getErrors()]); } }
public function hasAccess() { return Auth::getUserId() == $this->sender_id || Auth::getUserId() == $this->recipient_id; }