Book Store API Application Using Laravel 8 CRUD Operation
  • Learn how to create tables in MySQLdatabase with One-to-Manyand Many-to-Many relationships.
  • Implement the models and the functions that they serve.
  • Know how to implement CRUD with Laravel Resouce Controller
  • Get familiar with belongsToand belongsToManymethods

A simple definition of the project

Image by author

One-to-Many Relationship

Many-to-Many Relationship

Create Tables in Database

The publishers’ Table Structure
The books’ Table Structure
The authors’ Table Structure
The book_authors Table Structure

Create Models

The Publisher Model Structure
The BookAuthor Model Structure
The Author Model Structure

Create Controllers

  • The index function will be used to get a full list of all records.
  • In the store function after validating the requests, the new element will be created.
  • The show function is used to get the specific element by passing ID to the function.
  • We’re passing the ID to the destroy function and then detecting elements with the given ID and then deleting it.
  • The update function is used to update the given element based on the given requests.
The PublisherController Structure
The BookController Structure
The AuthorController Structure

Create Routes




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store