SlideShare una empresa de Scribd logo
1 de 45
Descargar para leer sin conexión
Building Scalable
applications with Laravel
Laravel - PHP Framework For Web Artisans
Lumen
The stunningly fast micro-framework by Laravel.
Lumen is the perfect solution for
building Laravel based
micro-services and blazing fast APIs
Laravel ● Middleware
● Dependency Injection
● Filesystem / Cloud Storage
● Queues
● Task Scheduling
● Database
○ Query Builder
○ Migrations
○ Seeding
● LUCID Architecture
Middleware
HTTP middleware provide a convenient mechanism for filtering
HTTP requests entering your application.
● Maintenance
● Authentication
● CSRF protection
MeetingMogul
Validate twilio requests (Header Signature)
<?php
namespace AppHttpMiddleware;
use Log;
use Closure;
use AppRepositoriesTwilioAccountTwilioAccountRepositoryInterface;
class ValidateTwilioRequestMiddleware
{
/**
* Handle an incoming request.
*
* @param IlluminateHttpRequest $request
* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$this->validateRequest($request)) {
throw new SymfonyComponentHttpKernelExceptionUnauthorizedHttpException('Twilio', 'You are not authorized to access this
resource.');
}
return $next($request);
}
}
Dependency Injection
Laravel provides a convenient way to inject dependencies
seemlessly.
<?php
namespace Database;
class Database
{
protected $adapter;
public function __construct(AdapterInterface $adapter)
{
$this->adapter = $adapter;
}
}
<?php
namespace AppApiv1Controllers;
use AppApiTransformersMessageStatusTransformer;
use AppRepositoriesUserUserRepositoryInterface;
/**
* Message Resource
*
* @Resource("Message", uri="/messages")
*/
class MessageController extends BaseController
{
protected $userRepo;
public function __construct(Request $request, UserRepositoryInterface $userRepo)
{
parent::__construct($request);
$this->userRepo = $userRepo;
}
protected function setMessagingStatus(Request $request)
{
$this->userRepo->createOrUpdateProfile($this->auth->user(), $request->all());
return (['message' => 'Message Status updated successfully.']);
}
}
<?php
namespace AppRepositories;
use IlluminateSupportServiceProvider;
class RepositoryServiceProvider extends ServiceProvider
{
/**
* @var array
*/
protected $bindings = [
UserUserRepositoryInterface::class => UserUserRepository::class,
BuddyBuddyRepositoryInterface::class => BuddyBuddyRepository::class,
ProfileProfileRepositoryInterface::class => ProfileProfileRepository::class,
ContentContentRepositoryInterface::class => ContentContentRepository::class,
];
/**
* @return void
*/
public function register()
{
foreach ($this->bindings as $interface => $implementation) {
$this->app->bind($interface, $implementation);
}
}
}
Cloud Storage
Laravel provides a powerful filesystem abstraction. It
provides simple to use drivers for working with Local
filesystems, Amazon S3 and Rackspace Cloud Storage. Even
better, it's amazingly simple to switch between these
storage options as the API remains the same for each system.
Cloud Storage
public function updateAvatar(Request $request, $id)
{
$user = User::findOrFail($id);
Storage::put(
'avatars/'.$user->id,
file_get_contents($request->file('avatar')->getRealPath())
);
}
Queues
The Laravel queue service provides a unified API across a
variety of different queue back-ends.
$job = (new SendReminderEmail($user))->onQueue('emails');
$this->dispatch($job);
Available Queue Drivers:
Database, Beanstalkd, Amazon SQS, Redis, and synchronous
(for local use) driver
Task Scheduling
The Laravel command scheduler allows you to fluently and
expressively define your command schedule within Laravel
itself, and only a single Cron entry is needed on your
server.
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
DB::table('recent_users')->delete();
})->daily();
$schedule->command('emails:send')->weekly()->mondays()->at('13:00');
$schedule->command('emails:send')->withoutOverlapping();
}
Database
Query Builder
Migrations
Seeding
Elequent ORM
Query Builder
DB::transaction(function () {
DB::table('users')->update(['votes' => 1]);
DB::table('posts')->delete();
});
Migrations
Migrations are like version control for your database.
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
});
Seeding
Laravel includes a simple method of seeding your database
with test data using seed classes.
<?php
use IlluminateDatabaseSeeder;
use IlluminateDatabaseEloquentModel;
class DatabaseSeeder extends Seeder
{
public function run()
{
DB::table('users')->insert([
'name' => str_random(10),
'email' => str_random(10).'@gmail.com',
'password' => bcrypt('secret'),
]);
}
}
Eloquent ORM
● Convention over configuration
● Timestamps automatically managed (Carbon)
● Soft Deleting
● Query Scopes
Eloquent ORM - Soft Delete
● Active Record implementation
php artisan make:model User --migration
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Flight extends Model
{
use SoftDeletes;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['deleted_at'];
}
LUCID
Architecture
An Architecture is a pattern of
connected Structures.
LUCID architecture Designed at vinelab
to get rid of rotting/legacy code.
Architecture
Controller View
Model
Service/
Domain
Communicate Structures
● No more legacy code
● Defines Terminology
● Comprehensive, No limitations
● Complements Laravel’s Design
● Balance performance and design
Lucid Components
Feature
Job
Service
Lucid * Feature
● As described in business, as a class name
● Runs Jobs - Steps in the process of accomplishment
CreateArticleFeature
LoginUserFeature
Controller Feature
Serves
Controller serves Feature
Lucid * Job
A class that does one thing; responsible for the business logic
● Validate Article Input
● Generate Slug
● Upload Files To CDN
● Save Article
● Respond With Json
CreateArticleFeature
Lucid * Job
A class that does one thing; responsible for the business logic
● ValidateArticleInputJob
● GenerateSlugJob
● UploadFilesToCDNJob
● SaveArticleJob
● RespondWithJsonJob
CreateArticleFeature
Lucid * Job
A class that does one thing; responsible for the business logic
Lucid * Service
Implements Features and serves them through controllers
● Website
● Api
● Backend
Lucid * Domains
Responsible for the entities; exposing their
functionalities through Jobs
Lucid * Domains
● Article
○ GetPublishedArticlesJob
○ SaveArticleJob
○ ValidateArticleInputJob
● CDN
○ UploadFilesToCdnJob
● HTTP
○ RespondWithJsonJob
Lucid * Principles
● Controllers serve Features
● Avoid Cross-Domain Communication
● Avoid Cross-Job Communication
Best Practices
● Standards (PHP-FIG)
○ Autoloading
○ Code Style
● Interfaces
● Components
○ Carbon
○ Intervention
● Pull Requests &
● Code Reviews on GitHub
Question & Answer

Más contenido relacionado

La actualidad más candente

Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Lorvent56
 
Laravel and CodeIgniter: pros & cons
Laravel and CodeIgniter: pros & consLaravel and CodeIgniter: pros & cons
Laravel and CodeIgniter: pros & consElenorWisozk
 
Laravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansLaravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansWindzoon Technologies
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 Joe Ferguson
 
Android Continuous Integration and Automation - Enrique Lopez Manas, Sixt
Android Continuous Integration and Automation - Enrique Lopez Manas, SixtAndroid Continuous Integration and Automation - Enrique Lopez Manas, Sixt
Android Continuous Integration and Automation - Enrique Lopez Manas, SixtDroidConTLV
 
Zen and the Art of REST API documentation - MuCon London 2015
Zen and the Art of REST API documentation - MuCon London 2015Zen and the Art of REST API documentation - MuCon London 2015
Zen and the Art of REST API documentation - MuCon London 2015Steve Judd
 
Testing Alfresco extensions
Testing Alfresco extensionsTesting Alfresco extensions
Testing Alfresco extensionsITD Systems
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Joe Ferguson
 
Laravelの良いところ
Laravelの良いところLaravelの良いところ
Laravelの良いところfagai
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipseMike Slinn
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introductionSimon Funk
 
Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021Colin O'Dell
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)Dave Haeffner
 
20171108 PDN HOL React Basics
20171108 PDN HOL React Basics20171108 PDN HOL React Basics
20171108 PDN HOL React BasicsRich Ross
 
Semi Automatic Code Review
Semi Automatic Code ReviewSemi Automatic Code Review
Semi Automatic Code ReviewRichard Huang
 

La actualidad más candente (20)

Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
Laravel and CodeIgniter: pros & cons
Laravel and CodeIgniter: pros & consLaravel and CodeIgniter: pros & cons
Laravel and CodeIgniter: pros & cons
 
Laravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansLaravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web Artisans
 
Laravel
LaravelLaravel
Laravel
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Android Continuous Integration and Automation - Enrique Lopez Manas, Sixt
Android Continuous Integration and Automation - Enrique Lopez Manas, SixtAndroid Continuous Integration and Automation - Enrique Lopez Manas, Sixt
Android Continuous Integration and Automation - Enrique Lopez Manas, Sixt
 
Zen and the Art of REST API documentation - MuCon London 2015
Zen and the Art of REST API documentation - MuCon London 2015Zen and the Art of REST API documentation - MuCon London 2015
Zen and the Art of REST API documentation - MuCon London 2015
 
Web presentation
Web presentationWeb presentation
Web presentation
 
Testing Alfresco extensions
Testing Alfresco extensionsTesting Alfresco extensions
Testing Alfresco extensions
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
 
Laravelの良いところ
Laravelの良いところLaravelの良いところ
Laravelの良いところ
 
Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
 
Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021Releasing High Quality Packages - Longhorn PHP 2021
Releasing High Quality Packages - Longhorn PHP 2021
 
Postman
PostmanPostman
Postman
 
How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)How To Use Selenium Successfully (Java Edition)
How To Use Selenium Successfully (Java Edition)
 
Functional Reactive Programming
Functional Reactive ProgrammingFunctional Reactive Programming
Functional Reactive Programming
 
20171108 PDN HOL React Basics
20171108 PDN HOL React Basics20171108 PDN HOL React Basics
20171108 PDN HOL React Basics
 
Semi Automatic Code Review
Semi Automatic Code ReviewSemi Automatic Code Review
Semi Automatic Code Review
 

Similar a Building Scalable Applications with Laravel

Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application ServerPhil Windley
 
laravel-interview-questions.pdf
laravel-interview-questions.pdflaravel-interview-questions.pdf
laravel-interview-questions.pdfAnuragMourya8
 
Memphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsMemphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsJoe Ferguson
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
Serverless APIs with JavaScript - Matt Searle - ChocPanda
Serverless APIs with JavaScript - Matt Searle - ChocPandaServerless APIs with JavaScript - Matt Searle - ChocPanda
Serverless APIs with JavaScript - Matt Searle - ChocPandaPaul Dykes
 
Extending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsExtending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsRaimonds Simanovskis
 
Decompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step FunctionsDecompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step FunctionsbeSharp
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with javaDPC Consulting Ltd
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsSebastian Springer
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleRaimonds Simanovskis
 
Ruby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingRuby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingDan Davis
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextPrateek Maheshwari
 
Laravel & Composer presentation - extended
Laravel & Composer presentation - extendedLaravel & Composer presentation - extended
Laravel & Composer presentation - extendedCvetomir Denchev
 
Serverless cat detector workshop - cloudyna 2017 (16.12.2017)
Serverless cat detector   workshop - cloudyna 2017 (16.12.2017)Serverless cat detector   workshop - cloudyna 2017 (16.12.2017)
Serverless cat detector workshop - cloudyna 2017 (16.12.2017)Paweł Pikuła
 

Similar a Building Scalable Applications with Laravel (20)

Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
Using Apache as an Application Server
Using Apache as an Application ServerUsing Apache as an Application Server
Using Apache as an Application Server
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
laravel-interview-questions.pdf
laravel-interview-questions.pdflaravel-interview-questions.pdf
laravel-interview-questions.pdf
 
Memphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basicsMemphis php 01 22-13 - laravel basics
Memphis php 01 22-13 - laravel basics
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
Intro to Laravel 4
Intro to Laravel 4Intro to Laravel 4
Intro to Laravel 4
 
Serverless APIs with JavaScript - Matt Searle - ChocPanda
Serverless APIs with JavaScript - Matt Searle - ChocPandaServerless APIs with JavaScript - Matt Searle - ChocPanda
Serverless APIs with JavaScript - Matt Searle - ChocPanda
 
Extending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on RailsExtending Oracle E-Business Suite with Ruby on Rails
Extending Oracle E-Business Suite with Ruby on Rails
 
Laravel Meetup
Laravel MeetupLaravel Meetup
Laravel Meetup
 
Grails 101
Grails 101Grails 101
Grails 101
 
Decompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step FunctionsDecompose the monolith into AWS Step Functions
Decompose the monolith into AWS Step Functions
 
Microservices and modularity with java
Microservices and modularity with javaMicroservices and modularity with java
Microservices and modularity with java
 
Divide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.jsDivide and Conquer – Microservices with Node.js
Divide and Conquer – Microservices with Node.js
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Ruby on Rails All Hands Meeting
Ruby on Rails All Hands MeetingRuby on Rails All Hands Meeting
Ruby on Rails All Hands Meeting
 
Apache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's NextApache Samza 1.0 - What's New, What's Next
Apache Samza 1.0 - What's New, What's Next
 
Knolx session
Knolx sessionKnolx session
Knolx session
 
Laravel & Composer presentation - extended
Laravel & Composer presentation - extendedLaravel & Composer presentation - extended
Laravel & Composer presentation - extended
 
Serverless cat detector workshop - cloudyna 2017 (16.12.2017)
Serverless cat detector   workshop - cloudyna 2017 (16.12.2017)Serverless cat detector   workshop - cloudyna 2017 (16.12.2017)
Serverless cat detector workshop - cloudyna 2017 (16.12.2017)
 

Último

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Último (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

Building Scalable Applications with Laravel

  • 1. Building Scalable applications with Laravel Laravel - PHP Framework For Web Artisans
  • 2. Lumen The stunningly fast micro-framework by Laravel. Lumen is the perfect solution for building Laravel based micro-services and blazing fast APIs
  • 3. Laravel ● Middleware ● Dependency Injection ● Filesystem / Cloud Storage ● Queues ● Task Scheduling ● Database ○ Query Builder ○ Migrations ○ Seeding ● LUCID Architecture
  • 4. Middleware HTTP middleware provide a convenient mechanism for filtering HTTP requests entering your application. ● Maintenance ● Authentication ● CSRF protection MeetingMogul Validate twilio requests (Header Signature)
  • 5. <?php namespace AppHttpMiddleware; use Log; use Closure; use AppRepositoriesTwilioAccountTwilioAccountRepositoryInterface; class ValidateTwilioRequestMiddleware { /** * Handle an incoming request. * * @param IlluminateHttpRequest $request * @param Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!$this->validateRequest($request)) { throw new SymfonyComponentHttpKernelExceptionUnauthorizedHttpException('Twilio', 'You are not authorized to access this resource.'); } return $next($request); } }
  • 6. Dependency Injection Laravel provides a convenient way to inject dependencies seemlessly. <?php namespace Database; class Database { protected $adapter; public function __construct(AdapterInterface $adapter) { $this->adapter = $adapter; } }
  • 7. <?php namespace AppApiv1Controllers; use AppApiTransformersMessageStatusTransformer; use AppRepositoriesUserUserRepositoryInterface; /** * Message Resource * * @Resource("Message", uri="/messages") */ class MessageController extends BaseController { protected $userRepo; public function __construct(Request $request, UserRepositoryInterface $userRepo) { parent::__construct($request); $this->userRepo = $userRepo; } protected function setMessagingStatus(Request $request) { $this->userRepo->createOrUpdateProfile($this->auth->user(), $request->all()); return (['message' => 'Message Status updated successfully.']); } }
  • 8. <?php namespace AppRepositories; use IlluminateSupportServiceProvider; class RepositoryServiceProvider extends ServiceProvider { /** * @var array */ protected $bindings = [ UserUserRepositoryInterface::class => UserUserRepository::class, BuddyBuddyRepositoryInterface::class => BuddyBuddyRepository::class, ProfileProfileRepositoryInterface::class => ProfileProfileRepository::class, ContentContentRepositoryInterface::class => ContentContentRepository::class, ]; /** * @return void */ public function register() { foreach ($this->bindings as $interface => $implementation) { $this->app->bind($interface, $implementation); } } }
  • 9. Cloud Storage Laravel provides a powerful filesystem abstraction. It provides simple to use drivers for working with Local filesystems, Amazon S3 and Rackspace Cloud Storage. Even better, it's amazingly simple to switch between these storage options as the API remains the same for each system.
  • 10. Cloud Storage public function updateAvatar(Request $request, $id) { $user = User::findOrFail($id); Storage::put( 'avatars/'.$user->id, file_get_contents($request->file('avatar')->getRealPath()) ); }
  • 11. Queues The Laravel queue service provides a unified API across a variety of different queue back-ends. $job = (new SendReminderEmail($user))->onQueue('emails'); $this->dispatch($job); Available Queue Drivers: Database, Beanstalkd, Amazon SQS, Redis, and synchronous (for local use) driver
  • 12. Task Scheduling The Laravel command scheduler allows you to fluently and expressively define your command schedule within Laravel itself, and only a single Cron entry is needed on your server. protected function schedule(Schedule $schedule) { $schedule->call(function () { DB::table('recent_users')->delete(); })->daily(); $schedule->command('emails:send')->weekly()->mondays()->at('13:00'); $schedule->command('emails:send')->withoutOverlapping(); }
  • 14. Query Builder DB::transaction(function () { DB::table('users')->update(['votes' => 1]); DB::table('posts')->delete(); });
  • 15. Migrations Migrations are like version control for your database. Schema::create('users', function (Blueprint $table) { $table->increments('id'); });
  • 16. Seeding Laravel includes a simple method of seeding your database with test data using seed classes. <?php use IlluminateDatabaseSeeder; use IlluminateDatabaseEloquentModel; class DatabaseSeeder extends Seeder { public function run() { DB::table('users')->insert([ 'name' => str_random(10), 'email' => str_random(10).'@gmail.com', 'password' => bcrypt('secret'), ]); } }
  • 17. Eloquent ORM ● Convention over configuration ● Timestamps automatically managed (Carbon) ● Soft Deleting ● Query Scopes
  • 18. Eloquent ORM - Soft Delete ● Active Record implementation php artisan make:model User --migration <?php namespace App; use IlluminateDatabaseEloquentModel; use IlluminateDatabaseEloquentSoftDeletes; class Flight extends Model { use SoftDeletes; /** * The attributes that should be mutated to dates. * * @var array */ protected $dates = ['deleted_at']; }
  • 19. LUCID Architecture An Architecture is a pattern of connected Structures. LUCID architecture Designed at vinelab to get rid of rotting/legacy code.
  • 22. ● No more legacy code ● Defines Terminology ● Comprehensive, No limitations ● Complements Laravel’s Design ● Balance performance and design
  • 24. Lucid * Feature ● As described in business, as a class name ● Runs Jobs - Steps in the process of accomplishment CreateArticleFeature LoginUserFeature Controller Feature Serves
  • 26.
  • 27.
  • 28.
  • 29.
  • 30. Lucid * Job A class that does one thing; responsible for the business logic ● Validate Article Input ● Generate Slug ● Upload Files To CDN ● Save Article ● Respond With Json CreateArticleFeature
  • 31. Lucid * Job A class that does one thing; responsible for the business logic ● ValidateArticleInputJob ● GenerateSlugJob ● UploadFilesToCDNJob ● SaveArticleJob ● RespondWithJsonJob CreateArticleFeature
  • 32. Lucid * Job A class that does one thing; responsible for the business logic
  • 33.
  • 34.
  • 35.
  • 36.
  • 37. Lucid * Service Implements Features and serves them through controllers ● Website ● Api ● Backend
  • 38.
  • 39.
  • 40. Lucid * Domains Responsible for the entities; exposing their functionalities through Jobs
  • 41. Lucid * Domains ● Article ○ GetPublishedArticlesJob ○ SaveArticleJob ○ ValidateArticleInputJob ● CDN ○ UploadFilesToCdnJob ● HTTP ○ RespondWithJsonJob
  • 42.
  • 43. Lucid * Principles ● Controllers serve Features ● Avoid Cross-Domain Communication ● Avoid Cross-Job Communication
  • 44. Best Practices ● Standards (PHP-FIG) ○ Autoloading ○ Code Style ● Interfaces ● Components ○ Carbon ○ Intervention ● Pull Requests & ● Code Reviews on GitHub

Notas del editor

  1. API architecture We need to use micro frameworks for APIs
  2. Laravel provides these features and it sets it apart from other PHP frameworks.
  3. Same as filters in Yii Can be defined Globally with route group
  4. Validate all requests coming from Twilio
  5. Problems DI solves are “Inversion of Control” and “Dependency Inversion Principle” Loosening dependencies by separate instantiation Depend on abstractions rather than concretions
  6. Dependency of UserRepository is injected automatically through Service Containers
  7. Service container bindings are registered in Service Providers We can replace these bindings with mock classes and testing can become simpler.
  8. Laravel uses flysystem library to provide filesystem abstraction.
  9. I guess Convention over Configuration is not specific to ORM In Laravel it has more use in ORM as compared to Ruby On Rails in which most of the framework features work on this principle
  10. Architecture: Outcome depends on how structures are connected. (DNA -> dinosaur) Old/legacy projects like Shredd/MTSobek New developer needs to understand where each piece of code resides
  11. How Structures (Classes) like any service connected to other part of our code High level or Top level view. An expression of a Viewpoint. Communicate Structures Large application code New developer MVC example
  12. Why use architecture Utility and Helper Classes Single Responsibility Principle
  13. Thin controller
  14. Autoloading (PSR-4) Code Style (PSR-2)