Laravel From Scratch: Part 16 - Add Comments The Way The Client Requests

preview_player
Показать описание
Imagine that you're building this little blog for a client. While speaking with them, they naturally bring up the fact that they'd like to have the ability to add comments to any post. Let's see if we can use that exact terminology in our code to provide a solution for them.

Рекомендации по теме
Комментарии
Автор

Just coming back to this for a refresh after having done many Laravel projects (even though we're well on to Laravel 10+ now) and I'm still realising there are some hidden gems, like using "create" on a hasMany relationship directly in the model!! I'd love to see an Laravel 11 from scratch update.

delmontee
Автор

How about getting this done when user_id has been added to the Comments table? i.e, to track the user who added the comments. I keep getting 'user_id' not having a default value error until I changed the addComment parameters to request(['body', 'user_id']) and the create() parameter of the Post model from compact('body') to $body in Laravel 5.5

ilesanmijohn
Автор

in 2.21, the action in html have an arguement of id, but how did the CommentController have the post as arguement instead of id only ?

titansofadotstore