Village Shop API that can list products depending on age, create new products with image and to delete existing products.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
Things you will need:
- PHP
- Composer
- Docker (optional)
- Laravel Valet (optional)
Things you might need to test API:
Make sure you have all required PHP extensions installed on your local machine https://laravel.com/docs/8.x/deployment#server-requirements
Clone the project
git clone git@github.com:Fecony/village_shop_api.git
Go to the project directory
cd village_shop_api
Copy .env.example file to .env on the root folder.
cp .env.example .env
By default, application is configured to run in Docker container. You don't have to change any environment configuration setting.
This command will run Docker container to install application dependencies You can refer to Laravel Sail docs for other useful commands!
docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php81-composer:latest \
composer install --ignore-platform-reqs
To run app in Docker container make sure that Docker is running.
./vendor/bin/sail up -d
Run ./vendor/bin/sail artisan key:generate
to generate app key.
Run ./vendor/bin/sail artisan storage:link
to create the symbolic link.
After you application is running in Docker container run ./vendor/bin/sail artisan migrate
to run migration files.
And also run ./vendor/bin/sail artisan db:seed
to seed your database.
composer install
To run application locally you have to change your .env
file mysql settings.
Change following settings to match your local mysql settings:
DB_HOST=127.0.0.1
DB_PORT=3306
# Change this settings to match you database name and mysql user
DB_DATABASE=laravel
DB_USERNAME=sail
DB_PASSWORD=password
Run php artisan key:generate
to generate app key.
Run php artisan storage:link
to create the symbolic link.
After that run php artisan migrate
to run migration files. And also run php artisan db:seed
to seed your database.
It is possible to run a job that will restock the products, to do this you need to run:
php artisan schedule:work
Or if you are using Docker:
./vendor/bin/sail artisan schedule:work
This page lists solutions to problems you might encounter. Here is a list of common problems.
- Try to run
./vendor/bin/sail down --rmi all -v
. It will remove all images used by any service and remove named volumes. - (optional) You might run
./vendor/bin/sail build --no-cache
to build image before running next command - Then run
./vendor/bin/sail up -d
again to build container.
Usually it happens when you have wrong permission set on storage folder.
Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: address already in use
Most likely you have running mysql service locally. There are 2 solutions to this issue:
- You have to stop your local mysql service to make port 3306 available for docker
- Use
FORWARD_DB_PORT
in your .env to use different port for docker port bindingFORWARD_DB_PORT=3307
- Thanks to Taylor Otwell for creating Laravel ✨
- Readme generator
For support, contact me @fecony.