Introduction

Welcome on this demo application. It tries to show how to use Symfony4+ php web application framework in a modern ways. It covers different usage: simple controller, call to external API, twig usage for more classic (old school ;-)) usage, and almost real SPA with REST or GraphQL API.
So, for the most complex samples, i used the following db model. Usually tutorial will only use a classic Book vs Review models. So it doesn't cover more complex ManyToMany relations with specific properties in the join tables. My model tries to be more complex. It will certainly not cover everything, but it may helps you to understand some complex parts.
You can participate on the github repository !
Database model
DB model

Here is the model used for this demo. There is differents relations type:

  • Books -> Serie: OneToMany -
    a book can be in a serie, a serie may have many books
  • Books -> Reviews: OneToMany -
    one book can have many reviews, a review is for only one book
  • Books -> Authors: ManyToMany through ProjectBookCreation join table that contains extra fields (so it's OneToMany between Book and ProjectBookCreation, and OneToMany between Editors and ProjectBookCreation -
    a book can have many authors, an author can write/draw/colorize many books
  • Books -> Editors: same as Authors but with ProjectBookEdition -
    a book can be published by many editors, an editor can publish many books
  • Books -> Tags: ManyToMany auto managed with Doctrine -
    a book can have many tags, a tag can be applied to many books
  • Readers -> Books: ManyToMany -
    a reader can own many books, a book can be owned by only one reader
  • Readers -> Loan: OneToMany -
    a reader can loan/borrow many books a to/from many readers
You may find it strange that Readers and Books is a ManyToMany relatinship. This is just to simplify the sample. In fact in a real library, a book can be owned by only one reader. To do that, i should link Readers to a ProjectBookEdition, and not a simple Book. This is because a Reader may owned a Book in different Edition. So we should also add extra properties like a date_entry and a price per example. So the relation between Readers and Books is more complex than it appears first.
I will certainly improve this in future, but i wanted the sample to be as simple as possible, but not too much to be able to see some complex relations.

Extra informations

Api Platform usage

Except Tags entity, all mapping is done throught Doctrine Entities. It benefits of all native extensions from ApiPlatform like Pagination, Sorting, and all others Filtering systems.
Tags entity is managed with DataProvider and DataPersister which is the recommenced pattern from [official documentation](https://api-platform.com/docs/core/design/). With Tags, the aim is to show how to use finely DataProvider and DataPersister with extensions systems (this is a Work In Progress).