protected function createFakeGroup(User $creator) { $group = Group::create(['created_at' => $this->faker->dateTimeThisDecade, 'creator_id' => $creator->getKey(), 'name' => $this->faker->city, 'description' => implode(' ', $this->faker->sentences(2)), 'sidebar' => $this->faker->paragraph, 'urlname' => $this->faker->domainWord]); $contentsNumber = $this->faker->numberBetween(0, 5); for ($i = 0; $i < $contentsNumber; $i++) { $this->createFakeContent($group); $this->createFakeEntry($group); } $subscribersNumber = $this->faker->numberBetween(0, count($this->users)); for ($i = 0; $i < $subscribersNumber; $i++) { $subscriber = $this->users[$i]; $this->createFakeSubscriber($group, $subscriber); } }
/** * Checks that user is not "myself" or is not blocked by notification target user */ public function isNotMyselfOrBlockedByReceiver(User $sourceUser, User $targetUser) { if ($targetUser->getKey() != $sourceUser->getKey() && !$targetUser->isBlockingUser($sourceUser)) { return true; } return false; }
public function isAuthor(User $user = null) { $userId = $user ? $user->getKey() : auth()->id(); return (int) $userId === (int) $this->user_id; }
public function canEdit(User $user = null) { $isAuthor = $user->getKey() == $this->user_id; $hasTime = $this->created_at->diffInMinutes() < 30; $isAdmin = $user->type == 'admin'; return $isAuthor && $hasTime || $isAdmin; }
private function getVoteElement($object, User $user) { if (!$object->votes()) { return false; } $vote = $object->votes()->where('user_id', $user->getKey())->first(); if (!$vote) { return false; } return $vote; }