PHP Technical Coding Task: Blog Application
Welcome Candidate!
This document outlines the task specifications for your coding assessment. Your goal is to create a simple blog application using Laravel. This task will test your technical, analytical, and problem-solving skills. Please read the requirements carefully and follow the guidelines to the best of your ability.
- Framework: Use Laravel to implement the backend and REST API.
- Composer Integration: Leverage Composer to manage dependencies.
- Time Management: You might not complete all tasks within the given time. Focus on demonstrating a good balance between quality and functionality.
- Questions: Feel free to ask if anything is unclear. Someone will be available to assist.
We value your efforts and look forward to seeing your implementation. Good luck!
- Use MySQL as your database.
- Design and implement a relational data model to meet the blog’s requirements.
- Use Laravel's Eloquent ORM for database interaction.
- Provide RESTful API endpoints to manage articles.
- Use appropriate HTTP methods (GET, POST, PUT, DELETE) for each operation.
-
Create an Article:
- Endpoint:
POST /api/articles
- Accepts JSON payload with
title
andcontent
. - Saves the article to the database with the current timestamp.
- Endpoint:
-
Edit an Article:
- Endpoint:
PUT /api/articles/{id}
- Accepts JSON payload with updated
title
and/orcontent
. - Updates the article in the database.
- Endpoint:
-
Delete an Article:
- Endpoint:
DELETE /api/articles/{id}
- Deletes the article from the database by its ID.
- Confirms deletion with a success message in the response.
- Endpoint:
-
View an Article:
- Endpoint:
GET /api/articles/{id}
- Returns the full content of the article, including its metadata.
- Endpoint:
-
List Articles:
- Endpoint:
GET /api/articles
- Returns a paginated list of articles with their IDs, titles, and creation dates.
- Supports query parameters for pagination (e.g.,
?page=1&limit=3
) and sorting (e.g.,?sort=date
).
- Endpoint:
-
Search Functionality:
- Endpoint:
GET /api/articles/search
- Accepts query parameters
q
to filter articles by keywords in thetitle
orcontent
.
- Endpoint:
-
Rate Limiting:
- Implement rate limiting to prevent abuse of endpoints.
- Sanitize and validate all user inputs to prevent SQL injection and other vulnerabilities.
- Use Laravel's validation rules for input validation.
- Implement token-based authentication (e.g., Laravel Sanctum) for secure access to create, edit, and delete operations.
- Follow Laravel’s conventions for controllers, models, and routes.
- Write clean, modular, and well-documented code.
- Ensure your variable and function names are descriptive and in English.
- Optimize database queries using Eloquent’s advanced features, such as eager loading.
- Use caching strategies for frequently accessed data (e.g., Laravel Cache).
- Use Laravel’s Resource Classes to transform API responses.
- Use Route Model Binding to simplify fetching models in your controllers.
- Take advantage of Laravel’s built-in pagination for listing articles.
We recommend using Docker to simplify the setup of your Laravel application and MySQL database. If you're familiar with Docker, set up containers for Laravel and MySQL for ease of development and testing.
Thank you for participating in this assessment. We look forward to reviewing your work!