public static function boot() { parent::boot(); static::deleting(function (Submission $submission) { Post::where('submissionId', $submission->id)->delete(); }); }
public function getIndex() { $pendingSubmissions = Submission::notApproved()->count(); $ordersNeedPrinting = Order::whereNull('printedAt')->count(); $ordersNeedShipping = Order::whereNull('shippedAt')->count(); $newMembers = User::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count(); $newPosts = Post::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count(); $newPosts += Comment::where('createdAt', '>=', date('Y-m-d 00:00:00'))->count(); return $this->view('admin::dashboard', ['pendingSubmissions' => $pendingSubmissions, 'ordersNeedPrinting' => $ordersNeedPrinting, 'ordersNeedShipping' => $ordersNeedShipping, 'newMembers' => $newMembers, 'newPosts' => $newPosts]); }
/** * - Send notification to the user * - Check if the user has earnt the sticker * * @param SubmissionApproved $event * * @return void */ public function handle(SubmissionApproved $event) { /** @var Post|null $post */ $post = Post::where('submissionId', $event->submission->id)->first(); if ($post) { EventLog::create(['type' => EventLog::TYPE_SUBMISSION_APPROVED, 'userId' => $event->submission->userId, 'taskId' => $event->submission->taskId, 'postId' => $post->id]); } $submission = $event->submission; $nm = new NotificationManager(); $notification = $nm->createNotification($submission->userId, Notification::TYPE_SUBMISSION_APPROVED); $notification->submissionId = $submission->id; $notification->taskId = $submission->taskId; $nm->saveNotification($notification); $task = $submission->task; $task->completedCount += 1; $task->save(); $pm = new ProgressManager($submission->user, $submission->task->sticker); if ($pm->completedSticker()) { $pm->giveSticker(); } $submission->getTask()->updateRating(); }
/** * @api {get} /posts/:postSlug Get A Single Posts * @apiGroup Task Posts * @apiDescription Returns a number of featured posts to display on the home page. * * @param string $slug * * @return Response */ public function show($slug) { $post = Post::where('slug', $slug)->firstOrFail(); $post->load(['task', 'task.sticker', 'images']); return $this->response(['post' => $post]); }