This project contains the implementation of Comment Approval System
, a Laravel service used to handle comments in a web application. The service provides methods for retrieving and updating comments using an instance of the Comment
model.
- PHP 8.x
- Laravel 9.x
- Clone the repository using
git clone <https://github.com/abbas-samadani/Approval_Comment>
- Install the required dependencies using Composer:
composer install
- Create a new MySQL database and update the .env file with your database credentials.
- Migrate the database:
php artisan migrate
The CommentService
provides the following methods:
Retrieve comments from the database.
public function getComments(string $orderBy, string $search = null): array;
$orderBy
(string, required): The field to order the comments by. Valid values are:nameAsc
,nameDesc
,dateAsc
,dateDesc
.$search
(string, optional): A search string to filter the comments by.
Returns an array of comments ordered by the specified field.
Update the approval status of a comment in the database.
public function updateApproval(int $id, bool $approved): object;
$id
(int, required): The ID of the comment to update.$approved
(bool, required): The new approval status of the comment.
Returns the updated comment as an object.
This project also provides two API endpoints for interacting with the CommentService
:
Retrieve comments from the database.
orderBy
(string, optional): The field to order the comments by. Valid values are:nameAsc
,nameDesc
,dateAsc
,dateDesc
.search
(string, optional): A search string to filter the comments by.
Returns a JSON object with an array of comments ordered by the specified field.
Update the approval status of a comment in the database.
approved
(bool, required): The new approval status of the comment.
Returns a JSON object with the updated comment.
To test this project, you can use the following command:
php artisan test
A React front-end is included in this project for displaying and approving comments. The front-end code is located in the front_end
directory.
- Node.js 12.x or above
- Move to the
front_end
directory:cd front_end
- Install the required dependencies using NPM or Yarn:
npm install
oryarn install
The front-end can be started using the following command from within the front_end
directory:
npm run dev
This command will start a development server at http://localhost:5173
. You can access the front-end by opening a web browser and navigating to this URL.
- Laravel - The PHP framework used
- React.js - The JavaScript library used
- Tailwind CSS
Abbas Samadani
The Laravel framework is open-sourced software licensed under the MIT license.