Laravel
The PHP Framework For Web Artisans
CRUD Operations Development
By Chen Alon
What is the acronym CRUD?
In computer programming, Create, Read, Update, and Delete are the four basic functions of
persistent storage.
Operation SQL REST API HTTP
Create INSERT .../resource PUT / POST
Read (Retrieve) SELECT .../resource/{id} | .../resource/{id}/resource GET
Update (Modify) UPDATE .../resource/{id} | .../resource/{id}/resource PUT / POST / PATCH
Delete (Destroy) DELETE .../resource/{id} | .../resource/{id}/resource DELETE
How you manage your CRUD operations?
An old project - managing CRUD operations
Do you see any problems?
Problems:
1. The controller class depends
on Eloquent.
2. It’s VERY hard to change the
data access layer.
3. Breaks the DRY principle
4. Adds responsibility to the
controller.
5. Breaks the SOLID principles.
So, how should we manage our CRUD?
(1) Use the Repository Design Pattern
So, how should we manage our CRUD?
(2) Follow the Don’t Repeat Yourself principle
The User Controller The User API Controller
So, how should we manage our CRUD?
(3) Follow the Dependency Inversion principle
Eloquent Implementation MongoDB Implementation
Summary & Resources
1) Use the Repository Design Pattern
Decouple the data layer from the business logic.
2) Follow the Don’t Repeat Yourself principle
Make sure your CRUD operations are available to use across the application.
3) Follow the Dependency Inversion principle (and SOLID in general)
Make sure you can switch your data layer easily.
Today you want to use Eloquent with MySQL,
Tomorrow you will have to switch to MongoDB.
Resources
● https://github.com/andersao/l5-repository/
● https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5/
● https://medium.com/beyond-the-manifesto/why-the-repository-pattern-is-ofte
n-misunderstood-in-the-laravel-community-e840780499f2
Laravel
BUILD SOMETHING AMAZING!
Thank You!

CRUD Operations Development

  • 1.
    Laravel The PHP FrameworkFor Web Artisans CRUD Operations Development By Chen Alon
  • 2.
    What is theacronym CRUD? In computer programming, Create, Read, Update, and Delete are the four basic functions of persistent storage. Operation SQL REST API HTTP Create INSERT .../resource PUT / POST Read (Retrieve) SELECT .../resource/{id} | .../resource/{id}/resource GET Update (Modify) UPDATE .../resource/{id} | .../resource/{id}/resource PUT / POST / PATCH Delete (Destroy) DELETE .../resource/{id} | .../resource/{id}/resource DELETE
  • 3.
    How you manageyour CRUD operations?
  • 4.
    An old project- managing CRUD operations Do you see any problems? Problems: 1. The controller class depends on Eloquent. 2. It’s VERY hard to change the data access layer. 3. Breaks the DRY principle 4. Adds responsibility to the controller. 5. Breaks the SOLID principles.
  • 5.
    So, how shouldwe manage our CRUD? (1) Use the Repository Design Pattern
  • 6.
    So, how shouldwe manage our CRUD? (2) Follow the Don’t Repeat Yourself principle The User Controller The User API Controller
  • 7.
    So, how shouldwe manage our CRUD? (3) Follow the Dependency Inversion principle Eloquent Implementation MongoDB Implementation
  • 8.
    Summary & Resources 1)Use the Repository Design Pattern Decouple the data layer from the business logic. 2) Follow the Don’t Repeat Yourself principle Make sure your CRUD operations are available to use across the application. 3) Follow the Dependency Inversion principle (and SOLID in general) Make sure you can switch your data layer easily. Today you want to use Eloquent with MySQL, Tomorrow you will have to switch to MongoDB. Resources ● https://github.com/andersao/l5-repository/ ● https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5/ ● https://medium.com/beyond-the-manifesto/why-the-repository-pattern-is-ofte n-misunderstood-in-the-laravel-community-e840780499f2
  • 9.