- Clone the repository
- Create a DB and update the .env file
- Run
composer install
- Run
php artisan migrate
- Run
php artisan db:seed
The seed command will create two users:
admin@example.com
with passwordadmin_password
: this user is an admineditor@example.com
with passwordeditor_password
: this user is an editor
- Run tests with
composer test
- Run PHPStan with
composer phpstan
- Run Pint with
composer format
-
POST /api/auth/login
- Logins a user and returns a token -
POST /api/admin/travels
- Creates a Travel
- Requires a valid token
- Requires the user to be an admin
POST /api/admin/travels/{travel}/tours
- Creates a Tour
- Requires a valid token
- Requires the user to be an admin
PUT /api/admin/travels/{travel}
- Edits a Travel
- Requires a valid token
- Requires the user to be an editor
POST /api/search
- Searches for Tours
You can use the Postman collection, WeRoad.postman_collection.json
, located in the root folder of this project to test the API.
This is a simple API project for WeRoad. It has a simple authentication system and two roles: admin and editor. The authentication system is based on Laravel Sanctum and the permissions are managed with Laravel Policies (TravelPolicy and TourPolicy).
API routes are located in the routes/api.php
file.
For this project, I used the following packages:
- Laravel Data: to manage requests and data objects
- Laravel Sluggable: to create slugs automatically
- Laravel Sanctum: for authentication
- Pest: for testing
- PHPStan: for static analysis
- Pint: for code formatting
- Faker: for seeding the database
The project has the following actions:
- Create a Travel
- Create a Tour
- Edit a Travel
I recently read this article: https://muhammedsari.me/unorthodox-eloquent and wanted to try the approach of a Pipeline
used for queries so I implemented it in this project.
The pipeline is located in the app/Actions/Search/SearchTours.php
file.
It's possible to run the tests with composer test
or ./vendor/bin/pest
. The tests are located in the tests
folder and are written with Pest.
It's possible to run PHPStan with composer analyse
. The PHPStan configuration is located in the phpstan.neon.dist
file.
I spent around 10 hours for this project. I mainly worked during lunch breaks and in the evening, with the exception of Friday afternoon (2/2/2024) when I was at home during the afternoon and worked on the project for a few hours more.
- The search pipeline could be improved with more filters and a better way to handle the query building
- The tests could be improved with more edge cases
- The code could be improved with better validation