-
app/Entities/Projects/Project.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Project extends Model { // public function comments() { return $this->morphMany(Comment::class, 'commentable'); } // }
-
app/Entities/Projects/Issue.php
Open in GitHubuse Illuminate\Database\Eloquent\Model; class Issue extends Model { // public function comments() { return $this->morphMany(Comment::class, 'commentable'); } }
-
app/Http/Controllers/Projects/CommentsController.php
Open in GitHubuse App\Entities\Projects\Comment; use App\Entities\Projects\Project; use App\Http\Controllers\Controller; use Illuminate\Http\Request; class CommentsController extends Controller { public function index(Project $project) { $this->authorize('view-comments', $project); $editableComment = null; $comments = $project->comments()->with('creator')->latest()->paginate(); if (request('action') == 'comment-edit' && request('comment_id') != null) { $editableComment = Comment::find(request('comment_id')); } return view('projects.comments', compact('project', 'comments', 'editableComment')); } public function store(Request $request, Project $project) { $this->authorize('comment-on', $project); $newComment = $request->validate([ 'body' => 'required|string|max:255', ]); $project->comments()->create([ 'body' => $newComment['body'], 'creator_id' => auth()->id(), ]); flash(__('comment.created'), 'success'); return back(); } // }