This Laravel project is aimed at creating a RESTful API to manage news articles, providing essential features for adding, updating, and deleting news. It also offers the capability to display a list of news articles in descending order of their publication date, excluding expired news.
- Create a new Laravel 10 application to get started.
- Configure a data model for news articles with the following fields:
- Title
- Content
- Category
- Start Date
- Expiration Date
- Create a data model for a hierarchical structure of news categories. Each category should have a name and a parent/child relationship, forming a tree of categories.
- Create a controller to handle CRUD operations for news articles, including creating, reading, updating, and deleting.
- Implement a middleware to restrict API access to authenticated users. Apply this middleware to API routes.
- Define API routes for CRUD operations on news articles, using HTTP methods (GET, POST, PUT, DELETE). Ensure that the API returns data in JSON format.
- Create a dedicated route to display news articles in descending order of their publication date, excluding expired news.
- Implement a recursive search algorithm that traverses the category hierarchy to find the requested category and retrieve all articles associated with that category and its subcategories.
- Develop a new API route to search for a specific category in the hierarchy based on its name and return all associated articles, including those from subcategories. Display only non-expired news articles in the results.
- Ensure that the API responds with the appropriate HTTP status codes for each operation, e.g., 200 for success, 201 for creation, 204 for deletion, 400 for request errors, etc.
Your work will be evaluated based on the following criteria:
- Correct setup of the Laravel application.
- Creation of the data model for news articles.
- Creation of a CRUD controller for news articles.
- Implementation of the user authentication middleware.
- Definition of API routes for CRUD operations.
- Correct display of the list of news articles as per the specified requirements.
- Appropriate API responses with correct HTTP status codes.
- To set up the category tree for the application, use the provided seeder to populate the categories and their hierarchy. Run the seeder to initialize the categories and their relationships.