Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

app/Entities/Projects/Project.php

Open in GitHub
use Illuminate\Database\Eloquent\Model;
 
class Project extends Model
{
//
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
//
}

app/Entities/Projects/Issue.php

Open in GitHub
use 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 GitHub
use 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();
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.