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 5 In Depth

9,429 views

Published on

Learn about some of the new features in Laravel 5, with a focus on the command pipeline, including a few opinions about how to use the pipeline in the best possible way to enforce a solid separation of concerns.

Published in: Software
  • If you want to download or read this book, copy link or url below in the New tab ......................................................................................................................... DOWNLOAD FULL PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Laravel 5 In Depth

  1. 1. LARAVEL 5 IN DEPTH Kirk Bushell
  2. 2. LARAVEL 5 IN DEPTH (sort of) Kirk Bushell
  3. 3. INTRODUCTION ● Developer - 15 years experience ● Technical lead - Tectonic Digital ● Software architect - Award Force - http://awardforce.com ● Information Technologies Coordinator - Engineers without Borders ● Technical writer - http://kirkbushell.me ● Twitter - @kirkbushell ● Github - https://github.com/kirkbushell
  4. 4. CAVEATS
  5. 5. ● Laravel 5 in 30 mins? Yeah… no. CAVEATS
  6. 6. ● Laravel 5 in 30 mins? Yeah… no. ● A whirlwind tour of Laravel 5 features, plus a few opinionated bits on good application structure and design. CAVEATS
  7. 7. ● Laravel 5 in 30 mins? Yeah… no. ● A whirlwind tour of Laravel 5 features, plus a few opinionated bits on good application structure and design. ● We’ll go over a user (member?) profile management use-case, with some perhaps ridiculous requirements. CAVEATS
  8. 8. LET’S GET STARTED
  9. 9. Route::get(‘user/profile’, ‘MemberController@profile’); Route::put(‘user/profile’, ‘MemberController@saveProfile’);
  10. 10. class MemberController { use DispatchesCommands; public function profile() { return view(‘member.profile’, [‘member’ => Auth::user()]); } public function saveProfile(SaveProfileRequest $request) { $this->dispatchFrom(SaveProfileCommand::class, $request); return redirect()->route(‘member.profile’); } }
  11. 11. class MemberController { use DispatchesCommands; public function profile() { return view(‘member.profile’, [‘member’ => Auth::user()]); } public function saveProfile(SaveProfileRequest $request) { $this->dispatchFrom(SaveProfileCommand::class, $request); return redirect()->route(‘member.profile’); } }
  12. 12. class MemberController { use DispatchesCommands; public function profile() { return view(‘member.profile’, [‘member’ => Auth::user()]); } public function saveProfile(SaveProfileRequest $request) { $this->dispatchFrom(SaveProfileCommand::class, $request); return redirect()->route(‘member.profile’); } }
  13. 13. class MemberController { use DispatchesCommands; public function profile() { return view(‘member.profile’, [‘member’ => Auth::user()]); } public function saveProfile(SaveProfileRequest $request) { $this->dispatchFrom(SaveProfileCommand::class, $request); return redirect()->route(‘member.profile’); } }
  14. 14. class MemberController { use DispatchesCommands; public function profile() { return view(‘user.profile’); } public function saveProfile(SaveProfileRequest $request) { $this->dispatchFrom(SaveProfileCommand::class, $request); return redirect()->route(‘member.profile’); } }
  15. 15. class SaveProfileRequest extends FormRequest { public function authorize() { return true; } public function rules() { return [ ‘username’ => [‘required’], ‘email’ => [‘required’, ‘email’] ]; } }
  16. 16. class SaveProfileRequest extends FormRequest { public function authorize() { return true; } public function rules() { return [ ‘username’ => [‘required’], ‘email’ => [‘required’, ‘email’] ]; } }
  17. 17. class SaveProfileRequest extends FormRequest { public function authorize() { return true; } public function rules() { return [ ‘username’ => [‘required’], ‘email’ => [‘required’, ‘email’] ]; } }
  18. 18. class MemberController { use DispatchesCommands; public function profile() { return view(‘user.profile’); } public function saveProfile(SaveProfileRequest $request) { $this->dispatchFrom(SaveProfileCommand::class, $request); return redirect()->route(‘member.profile’); } }
  19. 19. class SaveProfileCommand { public $username; public $email; public function __construct($username, $email) { $this->username = $username; $this->email = $email; } }
  20. 20. class SaveProfileCommandHandler { private $users; public function __construct(UserRepositoryInterface $users) { $this->users = $users; } public function handle(SaveProfileCommand $command) { ... } }
  21. 21. class SaveProfileCommandHandler { ... public function handle(SaveProfileCommand $command) { $user = Auth::user(); $user->username = $command->username; $user->email = $command->email; $this->users->save($user); Event::fire(new MemberProfileSaved($user)); } }
  22. 22. class SaveProfileCommandHandler { ... public function handle(SaveProfileCommand $command) { $user = Auth::user(); $user->username = $command->username; $user->email = $command->email; $this->users->save($user); Event::fire(new MemberProfileSaved($user)); } }
  23. 23. class SaveProfileCommandHandler { ... public function handle(SaveProfileCommand $command) { $user = Auth::user(); $user->username = $command->username; $user->email = $command->email; $this->users->save($user); Event::fire(new MemberHasUpdatedProfile($user)); } }
  24. 24. class SaveProfileCommandHandler { ... public function handle(SaveProfileCommand $command) { $user = Auth::user(); $user->username = $command->username; $user->email = $command->email; $this->users->save($user); Event::fire(new MemberHasUpdatedProfile($user)); } }
  25. 25. class MemberHasUpdatedProfile { public $user; public function __construct(User $user) { $this->user = $user; } }
  26. 26. use IlluminateFoundationSupportProvidersEventServiceProvider; class ServiceProvider extends EventServiceProvider { protected $listen = [ ‘MemberHasUpdatedProfile’ => [ ‘MemberListener@whenMemberHasUpdatedProfile’ ] ]; }
  27. 27. class MemberListener { use DispatchesCommands; public function whenMemberHasUpdatedProfile(User $member) { $this->dispatch( new SendNotificationCommand( $member, ‘profile.notification’, $member->email, ‘Profile updated’ ) ); } }
  28. 28. class MemberListener { use DispatchesCommands; public function whenMemberHasUpdatedProfile(User $member) { $this->dispatch( new SendNotificationCommand( $member, ‘profile.notification’, $member->email, ‘Profile updated’ ) ); } }
  29. 29. class MemberListener { use DispatchesCommands; public function whenMemberHasUpdatedProfile(User $member) { $this->dispatch( new SendNotificationCommand( $member, ‘profile.notification’, $member->email, ‘Profile updated’ ) ); } }
  30. 30. class SendNotificationCommand implements ShouldBeQueued { use SerializesModels; public $data; public $template; public $to; public $subject; public function __construct($data, $template, $to, $subject) { $this->data = $data; $this->template = $template; $this->to = $to; $this->subject = $subject; } }
  31. 31. class SendNotificationCommand implements ShouldBeQueued { use SerializesModels; public $data; public $template; public $to; public $subject; public function __construct($data, $template, $to, $subject) { $this->data = $data; $this->template = $template; $this->to = $to; $this->subject = $subject; } }
  32. 32. class SendNotificationCommand implements ShouldBeQueued { use SerializesModels; public $data; public $template; public $to; public $subject; public function __construct($data, $template, $to, $subject) { $this->data = $data; $this->template = $template; $this->to = $to; $this->subject = $subject; } }
  33. 33. class SendNotificationCommand implements ShouldBeQueued { use SerializesModels; public $data; public $template; public $to; public $subject; public function __construct($data, $template) { $this->data = $data; $this->template = $template; $this->to = $to; $this->subject = $subject; } }
  34. 34. class SendNotificationCommandHandler { public function handle(SendNotificationCommand $command) { $vars = [‘data’ => $command->data]; $handler = function($message) use ($command) { $message->to($command->to); $message->subject($command->subject); }; Mail::send($command->template, $vars, $handler); } }
  35. 35. class SendNotificationCommandHandler { public function handle(SendNotificationCommand $command) { $vars = [‘data’ => $command->data]; $handler = function($message) use ($command) { $message->to($command->to); $message->subject($command->subject); }; Mail::send($command->template, $vars, $handler); } }
  36. 36. class SendNotificationCommandHandler { public function handle(SendNotificationCommand $command) { $vars = [‘data’ => $command->data]; $handler = function($message) use ($command) { $message->to($command->to); $message->subject($command->subject); }; Mail::send($command->template, $vars, $handler); } }
  37. 37. class SendNotificationCommandHandler { public function handle(SendNotificationCommand $command) { $vars = [‘data’ => $command->data]; $handler = function($message) use ($command) { $message->to($command->to); $message->subject($command->subject); }; Mail::send($command->template, $vars, $handler); } }
  38. 38. class SendNotificationCommandHandler { public function handle(SendNotificationCommand $command) { $vars = [‘data’ => $command->data]; $handler = function($message) use ($command) { $message->to($command->to); $message->subject($command->subject); }; Mail::send($command->template, $vars, $handler); } }
  39. 39. ERMAHGERD! SOMEONE UPDATED MAH PROFILEZ!!!
  40. 40. SELF-HANDLING COMMANDS
  41. 41. ● Scared by all the code? SELF-HANDLING COMMANDS
  42. 42. ● Scared by all the code? ● Don’t worry - Laravel has you covered SELF-HANDLING COMMANDS
  43. 43. ● Scared by all the code? ● Don’t worry - Laravel has you covered ;) SELF-HANDLING COMMANDS
  44. 44. ● Scared by all the code? ● Don’t worry - Laravel has you covered ;) ● Possible to have commands handle themselves SELF-HANDLING COMMANDS
  45. 45. ● Scared by all the code? ● Don’t worry - Laravel has you covered ;) ● Possible to have commands handle themselves ● How? SELF-HANDLING COMMANDS
  46. 46. class SaveProfileCommand implements SelfHandling { public $username; public $email; public function __construct($username, $email) { $this->username = $username; $this->email = $email; } public function handle() { ... } }
  47. 47. class SaveProfileCommand implements SelfHandling { public $username; public $email; public function __construct($username, $email) { $this->username = $username; $this->email = $email; } public function handle() { ... } }
  48. 48. class SaveProfileCommand implements SelfHandling { ... public function handle() { $user = Auth::user(); $user->username = $this->username; $user->email = $this->email; ... } }
  49. 49. RECAP
  50. 50. ● Laravel’s command architecture rocks RECAP
  51. 51. ● Laravel’s command architecture rocks ● Helps us to easily isolate specific use-cases RECAP
  52. 52. ● Laravel’s command architecture rocks ● Helps us to easily isolate specific use-cases ● We can queue expensive or time-consuming tasks RECAP
  53. 53. ● Laravel’s command architecture rocks ● Helps us to easily isolate specific use-cases ● We can queue expensive or time-consuming tasks ● Commands indicate intention RECAP
  54. 54. ● Laravel’s command architecture rocks ● Helps us to easily isolate specific use-cases ● We can queue expensive or time-consuming tasks ● Commands indicate intention ● Easy to test, super easy to spot problems RECAP
  55. 55. ● Laravel’s command architecture rocks ● Helps us to easily isolate specific use-cases ● We can queue expensive or time-consuming tasks ● Commands indicate intention ● Easy to test, super easy to spot problems ● Events allow us to easily implement side-effects (such as email) RECAP
  56. 56. ● Laravel’s command architecture rocks ● Helps us to easily isolate specific use-cases ● We can queue expensive or time-consuming tasks ● Commands indicate intention ● Easy to test, super easy to spot problems ● Events allow us to easily implement side-effects (such as email) ● You can be as simple or as complex as you like RECAP
  57. 57. THANK YOU :)
  58. 58. THANK YOU :) ● http://kirkbushell.me ● https://github.com/kirkbushell ● @kirkbushell

×