Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Laravel, the right way - PHPConference 2016

858 Aufrufe

Veröffentlicht am

Laravel has a lot of features and an extremely simple architecture. It sometimes leads the programmer to make some mistakes, when it comes time to get the most out of it. Through practical and simple examples we will enter the world of Laravel, starting with the basics and ending with the architecture that Laravel uses.

Veröffentlicht in: Internet
  • Als Erste(r) kommentieren

Laravel, the right way - PHPConference 2016

  1. 1. 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
  2. 2. https://bosnadev.com/2015/03/07/using-repository-pattern-in-laravel-5
  3. 3. andersao/l5-repository
  4. 4. ├── ├── ├── ├── ├── ├── ├──
  5. 5. http://kamranahmed.info/blog/2015/12/03/creating-a-modular-application-in-laravel
  6. 6. ├── ├── ├── ├── ├── ├── ├── ├── ├── ├── ├── ├── ├── ├──
  7. 7. 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(), ]); }
  8. 8. 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
  9. 9. 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, ]); }
  10. 10. 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); }
  11. 11. $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'], ]; }
  12. 12. $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'], ]; }
  13. 13. $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'], ]; }
  14. 14. $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'], ])); }
  15. 15. // 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');
  16. 16. // 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');
  17. 17. // 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');
  18. 18. // 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');
  19. 19. $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'], ]; }
  20. 20. public function update(Request $request) { // do something return Auth::user()->id; }

×