A simple demonstration of a rest API with Laravel
First pull the git repository.
$ git clone https://github.com/jesse-greathouse/shop-manager.git
Switch to the shop-manager directory
$ cd shop-manager
Copy the environment file.
$ cp .env.example .env
Now that you have your environment file set up, open your environment file and update the MySQL configs to work in your local environment.
To initialize the database first run the migrations.
$ php artisan migrate
To run the application with an already established database, you must first seed the database.
$ php artisan db:seed
This application is for demonstration purposes. Simply run the development server.
$ php artisan serve
It will be easiest to interact with the application via an http request client like Postman.
You can download Postman here.
In the root of the repository, you will see some files meant for importing into Postman.
You can import the environment files by clicking on the cog-wheel in the upper right-hand corner of Postman.
Import the environment files:
- shop-manager-local.postman_environment.json
- shop-manager-production.postman_environment.json
Click the import button in the upper-right portion of Postman
Under the "Import File" tab, click Choose Files.
Import the collection:
- shop-manager.postman_collection.json
Now you can select the "shop-manager" workspace in postman, and you can also select the environment that you wish to use.
With the collection you imported into postman, you can make requests to any of the endpoints of the application. The requests in the collection already have pre-filled POST and PUT variables under the body tab.
The application comes equipped with its own database. It requires the use of Sqlite 3. Run the migrations with the following command.
$ php artisan migrate:fresh --env=testing
It is not necessary to seed the test database because the tests do not depend on existing data. However if you would like to seed the test database, it is possible with the following command.
$ php artisan db:seed --env=testing
As long as the migrations have been ran on the test database, you can run the tests simply with the following command.
$ php artisan test