This Laravel application provides an API to manage users. It includes endpoints to register users and retrieve user information with filtering options. Additionally, it features email verification using a job queue.
- PHP >= 8.3
- Composer
- MySQL (or any preferred database)
- Laravel 8.x or later
-
Clone the repository:
git clone <repository-url> cd <repository-directory>
-
Install dependencies:
composer install
-
Setup environment variables: Copy
.env.example
to.env
and configure your database settings.cp .env.example .env
-
Generate application key:
php artisan key:generate
-
Run database migrations:
php artisan migrate
-
Start the server:
php artisan serve
-
Start the queue worker: Open a new terminal and run:
php artisan queue:work
To seed the database with 100,000 users (a mix of verified and unverified users), run:
php artisan db:seed --class=UserSeeder
-
URL:
/api/user
-
Method: POST
-
Headers:
Content-Type: application/json
-
Body:
{ "name": "John Doe", "email": "john.doe@example.com" }
-
Response:
- Status: 201 Created
- Body:
{ "id": 1, "name": "John Doe", "email": "john.doe@example.com", "is_verified": false, "created_at": "2024-06-24T00:00:00.000000Z", "updated_at": "2024-06-24T00:00:00.000000Z" }
-
URL:
/api/users
-
Method: GET
-
Query Parameters:
is_verified
(optional): true or false to filter by verification status.
-
Response:
- Status: 200 OK
- Body:
[ { "id": 1, "name": "John Doe", "email": "john.doe@example.com", "is_verified": false, "created_at": "2024-06-24T00:00:00.000000Z", "updated_at": "2024-06-24T00:00:00.000000Z" }, ... ]
To test the application, you can use PHPUnit:
- Run the tests:
php artisan test
Logs for email verification are written to storage/logs/laravel.log
. Ensure your logging.php
configuration is set up correctly.
- Make sure to configure your
.env
file with appropriate settings for your environment. - The email verification is logged and not actually sent. This is for development and testing purposes.
- During high traffic periods (e.g., marketing campaigns), ensure your queue worker can handle the load by properly configuring the queue system.
- The task was clear, straightforward, and practical, providing a good learning experience.
- Setting up and running the queue worker correctly posed a challenge.
- Ensuring the seeder was fast and efficient with a large dataset required thoughtful consideration.
- Improved understanding of Laravel’s queue system functionality.
- Importance of optimizing database operations for performance.
- More detailed setup instructions for the queue worker would be beneficial.
- Including a mock or example for MailService could enhance clarity.
- Emphasizing logging and monitoring during high traffic periods could be beneficial.
- The exercise was practical and relevant to real-world scenarios.
- Effective use of Laravel’s features made the task feel cohesive and valuable.