Working with Comments

Advanced Security - PHP Register/Login System Advanced Security - PHP Register/Login System / How-to Last updated on Updated  Jan 16, 2019

If you want to work with ASComments class, first you need to create new object of that class. Although you can do it manually, it's recommended to just resolve it out of the container with all it's dependencies:

$comment = app('comment');

Adding New Comment

To insert new comment into database, you need $userId of user who is posting the comment and comment text.

Usually logged user is posting the comment (unless you want to make it different) and his user Id can be found inside the session, or you can get it from the container, as it is explained here.

To insert new comment, just call insertComment method and pass two mentioned parameters

$comment->insertComment($userId, $commentText);

User's Comments

If you want to get all comments from specific user, you need to do the following


Last X Comments

To get last X comments from database, just call getComments method and pass number of comments as parameter. If you call getComments without parameters, you will get last 7 comments from database.

$comment->getComments();   //returns last 7 comments
$comment->getComments(20); //returns last 20 comments