Courses / Laravel PHP for Beginners: Build a Blog
Lesson 8 of 9

Project Hands‑On: Add Comment Feature (Project 1)

Video by Ajay yadav on YouTube · 22 min. We did not make this video and we do not host it — watching it here still counts as a view for the creator.

Implement a simple one‑to‑many relationship: a Post has many Comments. Create a Comment model and migration, then add comments() method in Post. Newbies often forget to set the foreign key column name, leading to SQLSTATE[42S22] errors.

In production, comments are a common interactive feature. Validate comment content, associate it with the authenticated user, and display them under each post using eager loading (Post::with('comments')->find($id)).

Start learning free

Sign in with WhatsApp, your phone number, email or Google. No password. The same account carries your progress, your certificates and anything else you do with Nexgino later.

Sign in to continue

It takes about fifteen seconds.

Previous Next lesson All lessons