Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Laravel the right way

699 views

Published on

Light talk with aim in disseminate the good patterns to use with Laravel.

Topics like unit test, models and controllers were spoken.

Published in: Internet
  • Be the first to comment

  • Be the first to like this

Laravel the right way

  1. 1. Laravel The Right Way
  2. 2. marabesi @MatheusMarabesi
  3. 3. DISCLAIMER
  4. 4. MODELS
  5. 5. WRONG
  6. 6. MUCH BETTER
  7. 7. CONTROLLERS
  8. 8. WRONG
  9. 9. 1
  10. 10. 1 2
  11. 11. 1 B E T T E R 2 3
  12. 12. pingpong-labs/modules
  13. 13. modules/ ├── Blog/ ├── Assets/ ├── Config/ ├── Console/ ├── Database/ ├── Migrations/ ├── Seeders/ ├── Entities/ ├── Http/ ├── Controllers/ ├── Middleware/ ├── Requests/ ├── routes.php ├── Providers/
  14. 14. D.I
  15. 15. 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(), ]); }
  16. 16. 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, ]); }
  17. 17. 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); }
  18. 18. TESTING
  19. 19. PHPUnit_Framework_TestCase
  20. 20. PHPUnit_Framework_TestCase TestCase
  21. 21. PHPUnit_Framework_TestCase TestCase
  22. 22. Class TestCase
  23. 23. padraic/mockery
  24. 24. public function update(Request $request) { // do something return Auth::user()->id; }
  25. 25. WHAT CAN I DO ?
  26. 26. +

×