SlideShare a Scribd company logo
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
To put it simply, Repository pattern is a kind of
container where data access logic is stored. It hides the
details of data access logic from business logic. In other
words, we allow business logic to access the data object
without having knowledge of underlying data access
architecture. Mar 7, 2015
https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5
https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5
andersao/l5-repository
├──
├──
├──
├──
├──
├──
├──
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
http://kamranahmed.info/blog/2015/12/03/creating-a-modular-application-in-laravel
├──
├──
├──
├──
├──
├──
├──
├──
├──
├──
├──
├──
├──
├──
Laravel, the right way - PHPConference 2016
public function newDeal(Request $request) {
$data = $request->all();
// some stuff
$page = "new_deal/new_deal_" . $data['page'];
return view($page, [
'active_step' => $data['page'],
'template_step' => 'app_deal_steps',
'origin' => 'new_deal',
'title' => 'New Deal',
'customers' => new AppDeals(),
]);
}
public function newDeal(Request $request) {
$data = $request->all();
// some stuff
$page = "new_deal/new_deal_" . $data['page'];
return view($page, [
'active_step' => $data['page'],
'template_step' => 'app_deal_steps',
'origin' => 'new_deal',
'title' => 'New Deal',
'customers' => new AppDeals(),
]);
}
X
public function newDeal(Request $request, AppDeals $deal) {
$data = $request->all();
// some stuff
$page = "new_deal/new_deal_" . $data['page'];
return view($page, [
'active_step' => $data['page'],
'template_step' => 'app_deal_steps',
'origin' => 'new_deal',
'title' => 'New Deal',
'customers' => $deal,
]);
}
public function store(Request $request)
{
$result['message'] = 'Success';
try {
$data = $request->all();
$userId = Auth::user()->id;
$company = App::make(Company::class)
->where('created_by', $userId)
->first();
$company->save($data);
} catch (Exception $error) {
$result['message'] = $error->getMessage();
}
return response()->json($result);
}
Laravel, the right way - PHPConference 2016
$invoices = [];
foreach ($request as $each) {
$invoices[$each['send_date']] = [
'deal_id' => $each['deal_id'],
'company_id' => $companyId,
'invoice_id' => $each['invoice_id'],
'invoice_term' => Invoices::TERM_30,
'send_same_invoice' => $each['send_same_invoice'],
];
}
$invoices = [];
foreach ($request as $each) {
$invoices[$each['send_date']] = [
'deal_id' => $each['deal_id'],
'company_id' => $companyId,
'invoice_id' => $each['invoice_id'],
'invoice_term' => Invoices::TERM_30,
'send_same_invoice' => $each['send_same_invoice'],
];
}
$invoices = [];
foreach ($request as $each) {
$invoices[$each['send_date']] = [
'deal_id' => $each['deal_id'],
'company_id' => $companyId,
'invoice_id' => $each['invoice_id'],
'invoice_term' => Invoices::TERM_30,
'send_same_invoice' => $each['send_same_invoice'],
];
}
$invoices = new Collection();
foreach ($request as $each) {
$invoices->push(new Invoice([
'deal_id' => $each['deal_id'],
'company_id' => $companyId,
'invoice_id' => $each['invoice_id'],
'invoice_term' => Invoices::TERM_30,
'send_same_invoice' => $each['send_same_invoice'],
]));
}
// Retrieve the first item in the collection
$collection->get(0);
// Default value as fallback
$collection->get(0, 'default value');
// Retrieve using custom key
$collection->get('my_key');
// Custom key and fallback
$collection->get('my_key', 'default value');
// Retrieve the first item in the collection
$collection->get(0);
// Default value as fallback
$collection->get(0, 'default value');
// Retrieve using custom key
$collection->get('my_key');
// Custom key and fallback
$collection->get('my_key', 'default value');
// Retrieve the first item in the collection
$collection->get(0);
// Default value as fallback
$collection->get(0, 'default value');
// Retrieve using custom key
$collection->get('my_key');
// Custom key and fallback
$collection->get('my_key', 'default value');
// Retrieve the first item in the collection
$collection->get(0);
// Default value as fallback
$collection->get(0, 'default value');
// Retrieve using custom key
$collection->get('my_key');
// Custom key and fallback
$collection->get('my_key', 'default value');
$invoices = [];
foreach ($request as $each) {
$invoices[$each['send_date']] = [
'deal_id' => $each['deal_id'],
'company_id' => $companyId,
'invoice_id' => $each['invoice_id'],
'invoice_term' => Invoices::TERM_30,
'send_same_invoice' => $each['send_same_invoice'],
];
}
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
public function update(Request $request)
{
// do something
return Auth::user()->id;
}
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016
Laravel, the right way - PHPConference 2016

More Related Content

PDF
Laravel the right way
PDF
TDC 2016 (Florianópolis) - Vá para o próximo nível - Dicas e truques para a c...
PDF
ZCPE - PHP Conference 2015
PDF
TDC2015 Porto Alegre - Automate everything with Phing !
PDF
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
PDF
PHP and Rich Internet Applications
PDF
PHP and Rich Internet Applications
PDF
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -
Laravel the right way
TDC 2016 (Florianópolis) - Vá para o próximo nível - Dicas e truques para a c...
ZCPE - PHP Conference 2015
TDC2015 Porto Alegre - Automate everything with Phing !
Darkmira Tour PHP 2016 - Automatizando Tarefas com Phing
PHP and Rich Internet Applications
PHP and Rich Internet Applications
エロサイト管理者の憂鬱3 - Hokkaiodo.pm#4 -

What's hot (19)

PDF
Twib in Yokoahma.pm 2010/3/5
PDF
Blog Hacks 2011
TXT
PDF
Build your own RESTful API with Laravel
PDF
YAPC::Asia 2010 Twitter解析サービス
PPTX
14. CodeIgniter adaugarea inregistrarilor
PDF
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
PPTX
4. Php MongoDB view_data
PDF
Getting out of Callback Hell in PHP
TXT
Threading
PDF
WordPress: From Antispambot to Zeroize
PDF
Laravel - PHP For artisans
PPT
07 Php Mysql Update Delete
PPT
06 Php Mysql Connect Query
PDF
Codeigniter : Custom Routing - Manipulate Uri
PDF
PowerCMS X
PDF
次世代版 PowerCMS 開発プロジェクトのご紹介
PPTX
Database Management - Lecture 4 - PHP and Mysql
DOCX
Example code for the SADI BMI Calculator Web Service
Twib in Yokoahma.pm 2010/3/5
Blog Hacks 2011
Build your own RESTful API with Laravel
YAPC::Asia 2010 Twitter解析サービス
14. CodeIgniter adaugarea inregistrarilor
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
4. Php MongoDB view_data
Getting out of Callback Hell in PHP
Threading
WordPress: From Antispambot to Zeroize
Laravel - PHP For artisans
07 Php Mysql Update Delete
06 Php Mysql Connect Query
Codeigniter : Custom Routing - Manipulate Uri
PowerCMS X
次世代版 PowerCMS 開発プロジェクトのご紹介
Database Management - Lecture 4 - PHP and Mysql
Example code for the SADI BMI Calculator Web Service
Ad

Viewers also liked (14)

PDF
Control your house with the elePHPant - PHPConf2016
PDF
Reactive Laravel - Laravel meetup Groningen
PDF
Software Design Patterns in Laravel by Phill Sparks
PDF
Phing - PHP Conference 2015
PPT
7º Connecting Knowledge (PT-BR)
PDF
IoT powered by PHP and streams - PHPExperience2017
DOCX
Secciones estilos encabezados
PDF
scdevsumit 2016 - Become a jedi with php streams
PDF
TDC São Paulo 2016 - Become a jedi with php streams
PDF
Thirteen ways of looking at a turtle
PPTX
Laravel and SOLR
PPTX
Domain Driven Design using Laravel
PDF
Todos os passos para a certificação PHP - PHPExperience2017
PPTX
Qualitative and quantitative methods of research
Control your house with the elePHPant - PHPConf2016
Reactive Laravel - Laravel meetup Groningen
Software Design Patterns in Laravel by Phill Sparks
Phing - PHP Conference 2015
7º Connecting Knowledge (PT-BR)
IoT powered by PHP and streams - PHPExperience2017
Secciones estilos encabezados
scdevsumit 2016 - Become a jedi with php streams
TDC São Paulo 2016 - Become a jedi with php streams
Thirteen ways of looking at a turtle
Laravel and SOLR
Domain Driven Design using Laravel
Todos os passos para a certificação PHP - PHPExperience2017
Qualitative and quantitative methods of research
Ad

Similar to Laravel, the right way - PHPConference 2016 (20)

PDF
Database Design Patterns
PPTX
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
PDF
What's New In Laravel 5
PDF
Laravel tips-2019-04
PDF
Advanced Interfaces and Repositories in Laravel
PDF
Laravel 5 In Depth
PDF
Building RESTful APIs with Laravel A Complete Guide.pdf
PDF
Laravel - Speaking eloquent eloquently
PDF
Speaking Eloquent Eloquently
PDF
A resource oriented framework using the DI/AOP/REST triangle
DOCX
Ultimate Laravel Performance Optimization Guide
PDF
Bootstrat REST APIs with Laravel 5
PDF
SDPHP Lightning Talk - Let's Talk Laravel
PDF
ConFoo 2024 - Need for Speed: Removing speed bumps in API Projects
PDF
Web services with laravel
PDF
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
PPT
Web service with Laravel
PDF
50 Laravel Tricks in 50 Minutes
PDF
laravel tricks in 50minutes
PDF
dcs plus Catalogue 2015
Database Design Patterns
Key Insights into Development Design Patterns for Magento 2 - Magento Live UK
What's New In Laravel 5
Laravel tips-2019-04
Advanced Interfaces and Repositories in Laravel
Laravel 5 In Depth
Building RESTful APIs with Laravel A Complete Guide.pdf
Laravel - Speaking eloquent eloquently
Speaking Eloquent Eloquently
A resource oriented framework using the DI/AOP/REST triangle
Ultimate Laravel Performance Optimization Guide
Bootstrat REST APIs with Laravel 5
SDPHP Lightning Talk - Let's Talk Laravel
ConFoo 2024 - Need for Speed: Removing speed bumps in API Projects
Web services with laravel
Staying railsy - while scaling complexity or Ruby on Rails in Enterprise Soft...
Web service with Laravel
50 Laravel Tricks in 50 Minutes
laravel tricks in 50minutes
dcs plus Catalogue 2015

More from Matheus Marabesi (14)

PDF
IoT Project postmortem
PDF
Testing with Laravel - 7Masters 2018 (Laravel)
PDF
Laravel collections an overview - Laravel SP
PDF
Becoming an author - Sharing knowledge
PDF
Docker 101 - Getting started
PDF
Introduction to IoT and PHP - Nerdzão day #1
PDF
GDG Passo fundo - Apps with unit tests (Karma + jasmine + angular)
PDF
7masters - MongoDb
PDF
CK 10 - Automate all the things 2.0
PDF
TDC 2015 - Wearables no IoT (PT-BR)
PDF
From legacy code to continuous integration
PDF
Introduction to TDD (PHPunit examples)
PPTX
Arduino day 2015 - UFABC (PT-BR)
PDF
Web Sockets - HTML5
IoT Project postmortem
Testing with Laravel - 7Masters 2018 (Laravel)
Laravel collections an overview - Laravel SP
Becoming an author - Sharing knowledge
Docker 101 - Getting started
Introduction to IoT and PHP - Nerdzão day #1
GDG Passo fundo - Apps with unit tests (Karma + jasmine + angular)
7masters - MongoDb
CK 10 - Automate all the things 2.0
TDC 2015 - Wearables no IoT (PT-BR)
From legacy code to continuous integration
Introduction to TDD (PHPunit examples)
Arduino day 2015 - UFABC (PT-BR)
Web Sockets - HTML5

Recently uploaded (20)

PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
artificial intelligence overview of it and more
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
newyork.pptxirantrafgshenepalchinachinane
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
Exploring VPS Hosting Trends for SMBs in 2025
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPT
Ethics in Information System - Management Information System
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Introuction about ICD -10 and ICD-11 PPT.pptx
PptxGenJS_Demo_Chart_20250317130215833.pptx
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
522797556-Unit-2-Temperature-measurement-1-1.pptx
Module 1 - Cyber Law and Ethics 101.pptx
Introduction to Information and Communication Technology
artificial intelligence overview of it and more
Slides PDF The World Game (s) Eco Economic Epochs.pdf
newyork.pptxirantrafgshenepalchinachinane
Sims 4 Historia para lo sims 4 para jugar
SASE Traffic Flow - ZTNA Connector-1.pdf
Decoding a Decade: 10 Years of Applied CTI Discipline
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Exploring VPS Hosting Trends for SMBs in 2025
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
Ethics in Information System - Management Information System
Tenda Login Guide: Access Your Router in 5 Easy Steps
The New Creative Director: How AI Tools for Social Media Content Creation Are...

Laravel, the right way - PHPConference 2016

  • 11. To put it simply, Repository pattern is a kind of container where data access logic is stored. It hides the details of data access logic from business logic. In other words, we allow business logic to access the data object without having knowledge of underlying data access architecture. Mar 7, 2015 https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5
  • 37. public function newDeal(Request $request) { $data = $request->all(); // some stuff $page = "new_deal/new_deal_" . $data['page']; return view($page, [ 'active_step' => $data['page'], 'template_step' => 'app_deal_steps', 'origin' => 'new_deal', 'title' => 'New Deal', 'customers' => new AppDeals(), ]); }
  • 38. public function newDeal(Request $request) { $data = $request->all(); // some stuff $page = "new_deal/new_deal_" . $data['page']; return view($page, [ 'active_step' => $data['page'], 'template_step' => 'app_deal_steps', 'origin' => 'new_deal', 'title' => 'New Deal', 'customers' => new AppDeals(), ]); } X
  • 39. public function newDeal(Request $request, AppDeals $deal) { $data = $request->all(); // some stuff $page = "new_deal/new_deal_" . $data['page']; return view($page, [ 'active_step' => $data['page'], 'template_step' => 'app_deal_steps', 'origin' => 'new_deal', 'title' => 'New Deal', 'customers' => $deal, ]); }
  • 40. public function store(Request $request) { $result['message'] = 'Success'; try { $data = $request->all(); $userId = Auth::user()->id; $company = App::make(Company::class) ->where('created_by', $userId) ->first(); $company->save($data); } catch (Exception $error) { $result['message'] = $error->getMessage(); } return response()->json($result); }
  • 42. $invoices = []; foreach ($request as $each) { $invoices[$each['send_date']] = [ 'deal_id' => $each['deal_id'], 'company_id' => $companyId, 'invoice_id' => $each['invoice_id'], 'invoice_term' => Invoices::TERM_30, 'send_same_invoice' => $each['send_same_invoice'], ]; }
  • 43. $invoices = []; foreach ($request as $each) { $invoices[$each['send_date']] = [ 'deal_id' => $each['deal_id'], 'company_id' => $companyId, 'invoice_id' => $each['invoice_id'], 'invoice_term' => Invoices::TERM_30, 'send_same_invoice' => $each['send_same_invoice'], ]; }
  • 44. $invoices = []; foreach ($request as $each) { $invoices[$each['send_date']] = [ 'deal_id' => $each['deal_id'], 'company_id' => $companyId, 'invoice_id' => $each['invoice_id'], 'invoice_term' => Invoices::TERM_30, 'send_same_invoice' => $each['send_same_invoice'], ]; }
  • 45. $invoices = new Collection(); foreach ($request as $each) { $invoices->push(new Invoice([ 'deal_id' => $each['deal_id'], 'company_id' => $companyId, 'invoice_id' => $each['invoice_id'], 'invoice_term' => Invoices::TERM_30, 'send_same_invoice' => $each['send_same_invoice'], ])); }
  • 46. // Retrieve the first item in the collection $collection->get(0); // Default value as fallback $collection->get(0, 'default value'); // Retrieve using custom key $collection->get('my_key'); // Custom key and fallback $collection->get('my_key', 'default value');
  • 47. // Retrieve the first item in the collection $collection->get(0); // Default value as fallback $collection->get(0, 'default value'); // Retrieve using custom key $collection->get('my_key'); // Custom key and fallback $collection->get('my_key', 'default value');
  • 48. // Retrieve the first item in the collection $collection->get(0); // Default value as fallback $collection->get(0, 'default value'); // Retrieve using custom key $collection->get('my_key'); // Custom key and fallback $collection->get('my_key', 'default value');
  • 49. // Retrieve the first item in the collection $collection->get(0); // Default value as fallback $collection->get(0, 'default value'); // Retrieve using custom key $collection->get('my_key'); // Custom key and fallback $collection->get('my_key', 'default value');
  • 50. $invoices = []; foreach ($request as $each) { $invoices[$each['send_date']] = [ 'deal_id' => $each['deal_id'], 'company_id' => $companyId, 'invoice_id' => $each['invoice_id'], 'invoice_term' => Invoices::TERM_30, 'send_same_invoice' => $each['send_same_invoice'], ]; }
  • 60. public function update(Request $request) { // do something return Auth::user()->id; }