SlideShare a Scribd company logo
Topics Covered:
1. What is laravel.
2. Understanding Application life cycle with laravel.
3. Understanding Classes & their communication!
4. Discussing a scenario, and implementing it (v1).
5. Understanding some important concepts.
6. Implementing it with new concepts (v2).
7. Q / A
1. What is laravel ?
1. Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for
the development of web applications following the model–view–controller architectural pattern
and based on Symfony
2. It is a full stack framework AND also API framework as well
3. We’ll focus our discussion considering it as a API framework, i.e. excluding Sessions, Views,
etc.
4. We’ll be more focused on discussing patterns that improve our daily application development
process.
Application Life cycle
So many buzzwords !
- Service Provider
- Service Container
- Dependency Injection
- SOLID
- IoC
- Middleware
- etc
It’s all about Classes & their communication !
Object Graph ! ->
Let’s divide Classes into two categories !
1. Entities / Models
a. Hold attributes / properties, with setters / getters
b. Can have multiple objects, can be instantiated multiple times in a Request life cycle
c. E.g. Car, Engine, Seat, etc.
d. Can be dependent on other Models
2. Services
a. Holds behavior
b. Mostly likely instantiated once in Application life cycle
c. E.g. CreateCarService, GetAllCars etc
d. Can be dependent on other Services / Models
e. Can be Singleton
Classes communication, again !
Let’s consider a scenario !
1. Design and develop an API to
a. Create User
i. Stores user in mysql database
ii. Store user information in cache
iii. Stores user profile in mixpanel (This tool can be changed in future)
b. Get User
i. Gets User Information from cache
ii. If not present in cache, get from database
2. User has following properties
a. id (integer)
b. name (string)
c. email (string)
d. subscription (Subscription) [has One]
e. role (Role) [has One]
Implementation # 1 :
1. No separation of concerns
2. No services
3. No dependency injection
4. No Repositories
5. No use of Service Container
6. Can’t write unit tests
7. Not maintainable code !
Code available : https://github.com/khatritariq/laravel-clean-services (v1 routes)
Let’s solve these problems within same system, and
address them one by one !
But we need to understand few concepts before !
1. Dependency Injection (SOLID)
2. Single Responsibility principle (SOLID) by using ADR pattern
3. DRY (Don’t Repeat Yourself)
4. Service Pattern
5. Service Container / Service Provider
6. Repository Pattern
1- Dependency Injection
Dependency Injection in Services
Single Responsibility Principle
1. Use of ADR pattern
a. Single Controller (per action)
2. Controller to only be responsible for Input Validation and Transfer control to
Service
3. Single Service Class
4. A class should have only one reason to change
DRY (Don’t Repeat Yourself)
- With introduction of Services, we don’t have to repeat the Controller Code into
Commands, if the same program has to be executed via CLI
- Services help us not Repeat the same program at multiple places
Service / Service Container / Service Provider
Service Container
Service Container:
The Laravel service container is a powerful tool
for managing class dependencies and performing
dependency injection.
Service Provider
Service providers are the central place of all Laravel application bootstrapping. Your own
application, as well as all of Laravel's core services are bootstrapped via service providers.
Repository Pattern
Repository encapsulates methods that persist and retrieve your business data
with some kind of storage (e.g.: a database, cache, etc). Also generally we create
a Repository to each entity (model).
Overall application flow
Implementation # 2:
1. No separation of concerns (Addressed via ADR / Services)
2. No services (Addressed)
3. No dependency injection (Addressed)
4. No Repositories (Addressed)
5. No use of Service Container (Addressed)
6. Can’t write unit tests (Addressed)
7. Not maintainable code ! (Addressed)
Code available : https://github.com/khatritariq/laravel-clean-services (v2 routes)
Questions ?
Thank you !

More Related Content

PDF
Introducing Ruby/MVC/RoR
PDF
Spring MVC
PPTX
Http pipeline
PPTX
Http pipeline
PPT
Introduction to API Design: REST and Java
PPTX
Mule groovy
PPTX
Software Development with PHP & Laravel
PDF
Software design patterns in laravel by phill sparks
Introducing Ruby/MVC/RoR
Spring MVC
Http pipeline
Http pipeline
Introduction to API Design: REST and Java
Mule groovy
Software Development with PHP & Laravel
Software design patterns in laravel by phill sparks

Similar to Developing clean services using laravel (20)

PDF
Software Design Patterns in Laravel by Phill Sparks
PDF
SDPHP Lightning Talk - Let's Talk Laravel
PDF
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondo
PDF
Laravel intake 37 all days
PDF
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
PDF
Service-Oriented Architecture
PPTX
Building Large Scale PHP Web Applications with Laravel 4
PPTX
Introduction to Laravel Framework (5.2)
PDF
Building Scalable Applications with Laravel
PDF
Mastering Important Design Patterns in Laravel.pdf
PDF
Building RESTful APIs with Laravel A Complete Guide.pdf
PPTX
Eloquent workflow: delivering data from database to client in a right way
PDF
What's New In Laravel 5
PPTX
Laravel introduction
PDF
Latest Laravel Development Trends that will Rule in 2021 - Think Tanker
PDF
Laravel Web Development: A Comprehensive Guide
PDF
Hidden things uncovered about laravel development
PDF
What is the Role of Laravel in API Development?
PDF
Dependency Injection
DOCX
Ultimate Laravel Performance Optimization Guide
Software Design Patterns in Laravel by Phill Sparks
SDPHP Lightning Talk - Let's Talk Laravel
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpcondo
Laravel intake 37 all days
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
Service-Oriented Architecture
Building Large Scale PHP Web Applications with Laravel 4
Introduction to Laravel Framework (5.2)
Building Scalable Applications with Laravel
Mastering Important Design Patterns in Laravel.pdf
Building RESTful APIs with Laravel A Complete Guide.pdf
Eloquent workflow: delivering data from database to client in a right way
What's New In Laravel 5
Laravel introduction
Latest Laravel Development Trends that will Rule in 2021 - Think Tanker
Laravel Web Development: A Comprehensive Guide
Hidden things uncovered about laravel development
What is the Role of Laravel in API Development?
Dependency Injection
Ultimate Laravel Performance Optimization Guide
Ad

Recently uploaded (20)

PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
history of c programming in notes for students .pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
top salesforce developer skills in 2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Nekopoi APK 2025 free lastest update
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
Transform Your Business with a Software ERP System
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
System and Network Administraation Chapter 3
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Design an Analysis of Algorithms I-SECS-1021-03
Design an Analysis of Algorithms II-SECS-1021-03
Odoo Companies in India – Driving Business Transformation.pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
history of c programming in notes for students .pptx
How to Choose the Right IT Partner for Your Business in Malaysia
top salesforce developer skills in 2025.pdf
Reimagine Home Health with the Power of Agentic AI​
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Nekopoi APK 2025 free lastest update
Understanding Forklifts - TECH EHS Solution
Transform Your Business with a Software ERP System
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Upgrade and Innovation Strategies for SAP ERP Customers
System and Network Administraation Chapter 3
Odoo POS Development Services by CandidRoot Solutions
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Design an Analysis of Algorithms I-SECS-1021-03
Ad

Developing clean services using laravel

  • 1. Topics Covered: 1. What is laravel. 2. Understanding Application life cycle with laravel. 3. Understanding Classes & their communication! 4. Discussing a scenario, and implementing it (v1). 5. Understanding some important concepts. 6. Implementing it with new concepts (v2). 7. Q / A
  • 2. 1. What is laravel ? 1. Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern and based on Symfony 2. It is a full stack framework AND also API framework as well 3. We’ll focus our discussion considering it as a API framework, i.e. excluding Sessions, Views, etc. 4. We’ll be more focused on discussing patterns that improve our daily application development process.
  • 4. So many buzzwords ! - Service Provider - Service Container - Dependency Injection - SOLID - IoC - Middleware - etc
  • 5. It’s all about Classes & their communication ! Object Graph ! ->
  • 6. Let’s divide Classes into two categories ! 1. Entities / Models a. Hold attributes / properties, with setters / getters b. Can have multiple objects, can be instantiated multiple times in a Request life cycle c. E.g. Car, Engine, Seat, etc. d. Can be dependent on other Models 2. Services a. Holds behavior b. Mostly likely instantiated once in Application life cycle c. E.g. CreateCarService, GetAllCars etc d. Can be dependent on other Services / Models e. Can be Singleton
  • 8. Let’s consider a scenario ! 1. Design and develop an API to a. Create User i. Stores user in mysql database ii. Store user information in cache iii. Stores user profile in mixpanel (This tool can be changed in future) b. Get User i. Gets User Information from cache ii. If not present in cache, get from database 2. User has following properties a. id (integer) b. name (string) c. email (string) d. subscription (Subscription) [has One] e. role (Role) [has One]
  • 9. Implementation # 1 : 1. No separation of concerns 2. No services 3. No dependency injection 4. No Repositories 5. No use of Service Container 6. Can’t write unit tests 7. Not maintainable code ! Code available : https://github.com/khatritariq/laravel-clean-services (v1 routes)
  • 10. Let’s solve these problems within same system, and address them one by one ! But we need to understand few concepts before ! 1. Dependency Injection (SOLID) 2. Single Responsibility principle (SOLID) by using ADR pattern 3. DRY (Don’t Repeat Yourself) 4. Service Pattern 5. Service Container / Service Provider 6. Repository Pattern
  • 13. Single Responsibility Principle 1. Use of ADR pattern a. Single Controller (per action) 2. Controller to only be responsible for Input Validation and Transfer control to Service 3. Single Service Class 4. A class should have only one reason to change
  • 14. DRY (Don’t Repeat Yourself) - With introduction of Services, we don’t have to repeat the Controller Code into Commands, if the same program has to be executed via CLI - Services help us not Repeat the same program at multiple places
  • 15. Service / Service Container / Service Provider
  • 16. Service Container Service Container: The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection.
  • 17. Service Provider Service providers are the central place of all Laravel application bootstrapping. Your own application, as well as all of Laravel's core services are bootstrapped via service providers.
  • 18. Repository Pattern Repository encapsulates methods that persist and retrieve your business data with some kind of storage (e.g.: a database, cache, etc). Also generally we create a Repository to each entity (model).
  • 20. Implementation # 2: 1. No separation of concerns (Addressed via ADR / Services) 2. No services (Addressed) 3. No dependency injection (Addressed) 4. No Repositories (Addressed) 5. No use of Service Container (Addressed) 6. Can’t write unit tests (Addressed) 7. Not maintainable code ! (Addressed) Code available : https://github.com/khatritariq/laravel-clean-services (v2 routes)