/** * Execute the job. * * @return bool */ public function handle() { // Set the inquiry model data. $this->inquiry->user_id = auth()->id(); $this->inquiry->uuid = uuid(); $this->inquiry->category_id = $this->category->id; $this->inquiry->title = $this->request->input('title'); $this->inquiry->description = $this->request->input('description'); if ($this->category->manager === true) { // If the category requires manager approval, we'll retrieve the manager record. $manager = User::whereHas('roles', function (Builder $query) { $query->whereName('managers'); })->findOrFail($this->request->input('manager')); $this->inquiry->manager_id = $manager->id; // We'll send the manager a notification. $notification = new Notification($manager, 'emails.inquiries.created', ['inquiry' => $this->inquiry], function (Message $message) use($manager) { $message->subject('A New Request Requires Your Approval'); $message->to($manager->email); }); } if ($this->inquiry->save()) { // If the inquiry was successfully created, we'll // send out the notification if one has been set. if (isset($notification)) { $this->dispatch($notification); } return true; } return false; }
/** * Returns a new table of inquiry categories. * * @param \Illuminate\Database\Eloquent\Builder|Category $category * @param Inquiry $inquiry * * @return \Orchestra\Contracts\Html\Builder */ public function table($category, Inquiry $inquiry) { if ($category->exists) { // If the category exists we're looking to display it's children. $category = $category->children(); } else { // Otherwise we're displaying root nodes. $category = $category->whereIsRoot()->whereBelongsTo($inquiry->getTable()); } return $this->table->of('inquiries.categories', function (TableGrid $table) use($category) { $table->with($category)->paginate($this->perPage); $table->layout('pages.categories._table'); $table->column('name', function (Column $column) { $column->value = function (Category $category) { return link_to_route('inquiries.categories.index', $category->name, [$category->id]); }; }); $table->column('sub-categories', function (Column $column) { $column->value = function (Category $category) { return $category->children()->count(); }; }); $table->column('delete', function (Column $column) { $column->value = function (Category $category) { $route = 'inquiries.categories.destroy'; return link_to_route($route, 'Delete', [$category->id], ['data-post' => 'DELETE', 'data-title' => 'Delete Category?', 'data-message' => 'Are you sure you want to delete this category? All child categories will be destroyed.', 'class' => 'btn btn-xs btn-danger']); }; }); }); }
/** * Closes the current inquiry. * * @return bool */ public function handle() { if ($this->inquiry->isOpen()) { $this->inquiry->closed = true; return $this->inquiry->save(); } return false; }
/** * Approves the current inquiry. * * @throws AlreadyApprovedException * * @return bool */ public function handle() { if (!$this->inquiry->isApproved()) { // Close the inquiry while approving. $this->dispatch(new Close($this->inquiry)); // Set the inquiry to approved. $this->inquiry->approved = true; // Reset the inquiries UUID. $this->inquiry->uuid = null; // Save the inquiry. return $this->inquiry->save(); } throw new AlreadyApprovedException('This request has already been approved.'); }
/** * Delete's the specified inquiry. * * @param int|string $id * * @return \Illuminate\Http\RedirectResponse */ public function destroy($id) { $inquiry = $this->inquiry->findOrFail($id); $this->authorize('inquiries.destroy', [$inquiry]); if ($inquiry->delete()) { flash()->success('Success!', 'Successfully deleted request.'); return redirect()->route('inquiries.index'); } flash()->error('Error!', 'There was an issue deleting this request. Please try again.'); return redirect()->route('inquiries.show', [$id]); }
/** * Deletes the specified comment. * * @param int|string $inquiryId * @param int|string $commentId * * @return \Illuminate\Http\RedirectResponse */ public function destroy($inquiryId, $commentId) { $inquiry = $this->inquiry->findOrFail($inquiryId); $comment = $inquiry->comments()->findOrFail($commentId); $this->authorize('comments.destroy', [$comment]); $inquiry->comments()->detach($comment); if ($comment->delete()) { flash()->success('Success!', 'Successfully deleted comment.'); return redirect()->route('inquiries.show', [$inquiryId]); } flash()->error('Error!', 'There was an issue deleting this comment. Please try again.'); return redirect()->route('inquiries.show', [$inquiryId]); }
/** * Execute the job. * * @return bool */ public function handle() { $this->inquiry->title = $this->request->input('title', $this->inquiry->title); $this->inquiry->description = $this->request->input('description', $this->inquiry->description); return $this->inquiry->save(); }
/** * Applies the issue policy to the issue query. * * @param Inquiry|Builder $inquiry * * @return Builder */ protected function applyPolicy($inquiry) { // Limit the view if the user isn't // allowed to view all issues. if (Auth::user()->cannot('manage.inquiries')) { $inquiry->where('user_id', auth()->user()->id); } return $inquiry; }