This project serves as a learning resource for creating a CRUD API with Laravel. It includes a Laravel project, API endpoints, and a Postman workspace for testing.
This project covers the following topics and features:
- Creating a Laravel project
- Implementing CRUD operations for an Instructor model
- API resource controllers and routes
- API versioning
- Database seeding and factories
- Using Postman for API testing
To get started with this project, follow these steps:
-
Clone the repository to your local machine:
git clone https://github.com/your_username/REST_API_Laravel.git
-
Navigate to the project directory:
cd REST_API_Laravel
-
Install Composer dependencies, create a copy of .env, and generate an application key:
composer install cp .env.example .env php artisan key:generate
-
Configure the database by opening .env in a text editor and setting the database connection settings. After making changes, save the file and exit the text editor:
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=rest_api # Set the database name to 'rest_api' DB_USERNAME=root # Your database username DB_PASSWORD= # Your database password
-
Create a new database named 'rest_api' in your MySQL database management tool:
-
Run database migrations and seed the database:
php artisan migrate php artisan db:seed --class=InstructorsTableSeeder
-
Start the Laravel development server:
php artisan serve
-
Import the provided Postman workspace for testing (use the workspace file "Laravel_CRUD_API.postman_workspace" located in the root directory).
-
Explore and test the API endpoints using Postman:
Here are the API endpoints provided by this project:
- List Instructors (GET):
/api/instructors
- Create Instructor (POST):
/api/instructors
- View Instructor (GET):
/api/instructors/{id}
- Update Instructor (PUT):
/api/instructors/{id}
- Delete Instructor (DELETE):
/api/instructors/{id}
Contributions to this project are welcome. Feel free to open issues, submit pull requests, or provide feedback.
This project is open-source and available under the MIT License.