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.

Laravel5 introduction (2014/11/20)

3,461 views

Published on

1. New Folder Structure & App Namespace
2. Spiffy Authentication
3. Contracts & Method Injection
4. Form Requests
5. Multiple Filesystem (Flysystem based)
6. Socialite (BETA)
7. Elixer
8. New Environment Detection
9. Route Annotation
10. Event Annotation
11. Route Caching
12. New File Generator

Published in: Software
  • Be the first to comment

Laravel5 introduction (2014/11/20)

  1. 1. Laravel5 Introduc0on Laravel Tokyo Camp Vol.1 2014/11/20 ྂᕝ㻌ᩥ⏕ ஭ୖ㻌⩧ኴ
  2. 2. 㻸aravel5䛾⣔㆕ • 2014ᖺ6᭶ – Laravel4.2䝸䝸䞊䝇䠄᭱᪂∧䛿4.2.11䠅 • 2014ᖺ9᭶ – 㛤Ⓨ୰䛾Laravel4.3䛾ྡ⛠䜢Laravel5.0䛻ኚ᭦ • 2014ᖺ11᭶⌧ᅾ – Laravel 5.0-­‐DEV䚸Dras0c䛻ኚ᭦䛺䛖
  3. 3. 㻸aravel5䛷ఱ䛜ኚ䜟䜛䛾䛛䠛 • ⬺Web䝣䝺䞊䝮䝽䞊䜽䠄⬺Rails䠅 • PHPྡ๓✵㛫ཷ䛡ධ䜜ࠥ䝣䜯䝃䞊䝗䛿䛔䛪䛣䠛䠛 • እ㒊Web䝃䞊䝡䝇㐃ᦠ䛾⤌䜏㎸䜏
  4. 4. 㻸aravel5㻦㻌䝧䞊䝇䜰䞊䜻䝔䜽䝏䝱 1. New Folder Structure App Namespace 䜰䝥䝸ᵓ㐀ᨵ㠉䛸PHPྡ๓✵㛫䛾ᙉไ䚹 2. Spiffy Authen0ca0on 䝴䞊䝄䞊ㄆド䝟䝑䜿䞊䝆䛔䜙䛪䟿䠛 3. 㻯ontracts Method Injec0on 䛥䜘䛖䛺䜙䝣䜯䝃䞊䝗䚹 4. Form Requests 䜸䞊䝖䝞䝸䝕䞊䝅䝵䞁䚹
  5. 5. 㻸aravel5㻦㻌᪂ᶵ⬟ 5. Mul0ple Filesystem (Flysystem based) 䝣䜯䜲䝹I/O䜢䜽䝷䜴䝗䝇䝖䝺䞊䝆䛻䜒⡆༢䛻䚹 6. Socialite (BETA) SNSㄆド䜢䛚ᡭ㍍䛻䚹 7. Elixer Laravel䛻⤫ྜ䛥䜜䛯Web䜰䝉䝑䝖⟶⌮䚹
  6. 6. 㻸aravel5㻦㻌䛭䛾䜋䛛䛻䜒 8. New Environment Detec0on 䝅䝇䝔䝮⎔ቃ䛻タᐃ䛧䛺䛔⎔ቃኚᩘ䛾Ⓩሙ䚹 9. Route Annota0on Pyramidⓗ䛺䚸䜰䝺䚹 10. 㻱vent Annota0on Javaⓗ䛺䚸䜰䝺䚹 11. Route Caching 12. New File Generator
  7. 7. 㻺ew Folder Structure 䞉Laravel䜢㉳ື䛩䜛䜰䝥䝸䜿䞊䝅䝵䞁䝍䜲䝥䛤䛸䛻䝣䜷䝹䝎䛜⏝ព䛥䜜䜛 app/Console app/H`p 䞉䜰䝥䝸䜿䞊䝅䝵䞁䝍䜲䝥䛤䛸䛻䜸䝤䝆䜵䜽䝖ᵓᡂ䜢ᣦᐃ䛩䜛Kernel䛜ᑟධ䛥䜜 䜛 app/Console/Kernel.php 䜰䝥䝸ᅛ᭷䛾ar0san䝁䝬䞁䝗ᐃ⩏䛺䛹䚹 app/H`p/Kernel.php middleware䛾ᐃ⩏䛺䛹䚹 1/12
  8. 8. New Folder Structure 1/12 Laravel5 Laravel4 㼍pp/Console/Commands 㼍pp/commands 㼍pp/H`p/Controllers 㼍pp/controllers 㼏㼛nfig 㼍pp/config database 㼍pp/database 㼞esource/lang 㼍pp/lang 㼞esources/views 㼍pp/views bootstrap bootstrap public public tests tests
  9. 9. 㻭pp Namespace 1/12 Before:Laravel4 Aker:Laravel5 㻨?php 㼏lass DashboardController { // … } 㻨?php namespace AppH`pControllers; 㼏lass Dashboard㻯ontroller { // … 㼩
  10. 10. 㻭pp Namespace 1/12 䞉PHPྡ๓✵㛫䛜ᙉไ䛥䜜䜛䜘䛖䛻䛺䛳䛯䚹 䞉ᣦᐃ⟠ᡤ䛿composer.json 䞉`php ar0san app:name` 䝁䝬䞁䝗䛷୍ᣓኚ᭦ྍ⬟䚹 䞉䝣䜯䝃䞊䝗䛜⣲┤䛻౑䛘䛺䛟䛺䛳䛯䚹 䞉䝣䜯䝃䞊䝗䜽䝷䝇䛿䜾䝻䞊䝞䝹ྡ๓✵㛫䛻䛒䜛䚹
  11. 11. 㻭pp Namespace 1/12 䞉䝣䜯䝃䞊䝗ၥ㢟 appୗ䛻PHPྡ๓✵㛫䛜タᐃ䛥䜜䜛䜘䛖䛻䛺䛳䛯䛯䜑䚸`Log::debug()`䛸᭩䛟䛸Log䜽䝷䝇䛜 ゎỴ䛷䛝䛪䜶䝷䞊䛸䛺䜛䚹Laravel4䛷䜒PHPྡ๓✵㛫䜢౑䛳䛶䛔䜜䜀ྠ䛨ၥ㢟䛜㉳䛝䜛䚹 㻌㻌㻌㻌㻌ゎỴ᪉ἲ䛿3䛴䚹 㻌㻌㻌㻌㻌1. useᩥ䜢౑䛖䚹 㻌㻌㻌㻌㻌㻌㻌㻌㻌㻌use Log; class DashboardController extends Controller { … } 2. 䝣䜯䝃䞊䝗䛾᏶඲ಟ㣭ྡ䜢ᣦᐃ䛩䜛䚹 㻌㻌㻌㻌㻌㻌㻌㻌㻌㻌public func0on getIndex() { Log::debug(__METHOD__); }
  12. 12. 㻭pp Namespace 1/12 䞉䝣䜯䝃䞊䝗ၥ㢟䠄⥆䛝䠅 3. laravel-­‐plus/extension䝟䝑䜿䞊䝆䜢ධ䜜䜛䚹app/addonୗ䛾ྡ๓✵㛫ෆ䛷䝣䜯䝃䞊䝗䜽䝷 䝇䜢⮬ືゎỴ䛧䛶䛟䜜䜛䚹 Laravel5-­‐DEV “require”: { “laravel-­‐plus/extension: dev-­‐master” } Laravel4 “require”: { laravel-­‐plus/extension: “~1.0” } 䈜laravel-­‐plus/extension䜢⤌䜏㎸䜏῭䜏䛾䝥䝻䝆䜵䜽䝖䝇䜿䝹䝖䞁䛿௨ୗ䛷⏕ᡂྍ⬟ composer create-­‐project laravel-­‐plus/laravel5=dev-­‐master project-­‐name
  13. 13. Spiffy Authen0ca0on 2/12 • ᶆ‽䛷 䚷㻌AuthController.php PasswordController 䛜㏣ຍ䛥䜜䛯䟿 →ㄆド㛵㐃䛷䝟䝑䜿䞊䝆䛻㢗䜛䛣䛸䛜↓䛟䛺䜛䠛 →Controller䛿⏝ព䛥䜜䛶䛔䜛䛜⣣䛵䛟View䛿⏝ព䛥䜜䛶䛔䛺䛔䞉䞉䞉
  14. 14. 㻯ontracts Method Injec0on 3/12 䞉Contracts = 䜲䞁䝍䞊䝣䜵䞊䝇䜽䝷䝇䛯䛱 䞉䜰䝥䝸䜿䞊䝅䝵䞁䝁䞁䝔䝘ෆ䛻䛒䜛඲䛶䛾䜸䝤䝆䜵䜽䝖䛻䜲䞁䝍䞊䝣䜵䞊䝇䛜 ㏣ຍ䛥䜜䛯䚹 Illuminate/Contractsྡ๓✵㛫 䝣䜯䝃䞊䝗䜘䜚䜲䞁䝆䜵䜽䝅䝵䞁䠄䝁䞁䝇䝖䝷䜽䝍䞉䝯䝋䝑䝗䠅᥎ዡ䟿䠛
  15. 15. 㻯ontracts 3/12 Method Injec0on 䈜Laravelᮾி䝇䜽䞊䝹㈨ᩱ䜘䜚ᢤ⢋
  16. 16. 㻯ontracts 3/12 Method Injec0on 䈜Laravelᮾி䝇䜽䞊䝹㈨ᩱ䜘䜚ᢤ⢋
  17. 17. 㻯ontracts 3/12 Method Injec0on 䜽䝻䞊䝆䝱䛻䜒ᣦᐃ䛷䛝䜛䟿 䈜Laravelᮾி䝇䜽䞊䝹㈨ᩱ䜘䜚ᢤ⢋
  18. 18. Form Requests 4/12 • ௒䜎䛷䛾Valida0on䛿routes.php䛛Controller 䛻᭩䛟䛺䛹䛷ᑐᛂ䚹 →Request䜢సᡂ䛧䚸౑⏝䛧䛯䛔䝯䝋䝑䝗䛻ᑐ䛧䛶䜲䞁䝆䜵䜽䝅䝵䞁䜢⾜䛖ᙧ䛻 ኚ᭦䛥䜜䛯䟿
  19. 19. 4/12௒䜎䛷䛾Valida0on
  20. 20. 䛣䜜䛛䜙䛾Valida0on 4/12 • Valida0onRule䛺䛹グ㏙䛧䛯䚸 FormRequests䜽䝷䝇䜢సᡂ䛩䜛䚹 • ౑⏝䛩䜛䝯䝋䝑䝗䛻䜲䞁䝆䜵䜽䝅䝵䞁䛩䜛䚹
  21. 21. Mul0ple Filesystem 5/12 䞉䝣䜯䜲䝹䛾ಖᏑඛ䛻Web䝇䝖䝺䞊䝆䜢㑅ᢥ䛷䛝䜛䜘䛖䛻䛺䜛䚹 䝻䞊䜹䝹 ($root/storage/app䝣䜷䝹䝎) AWS S3 Rackspace 䞉Flysys㼠em (by PHP League)䜢䝧䞊䝇䛸䛧䛶䛔䜛䚹 䈜Dropbox䛿Flysys㼠em䛷䜒䜸䝥䝅䝵䞁ᢅ䛔䛺䛾䛷䚸Laravel5䛷䝃䝫䞊䝖䛺 䛧䠛
  22. 22. Mul0ple Filesystem 5/12 䞉タᐃ config/filesystems.php 䞉䜸䝤䝆䜵䜽䝖䛾ྲྀᚓ app(‘filesystem.disk’) -­‐ config䛾’filesystems.default’䛷ᣦᐃ app(‘filesystem.cloud’) -­‐ config䛾’filesystem.cloud’䛷ᣦᐃ 䞉䜲䞁䝆䜵䜽䝅䝵䞁 IlluminateContractsFilesystemFilesystem = app(‘filesystem.disk’) IlluminateContractsFilesystemCloud = app(‘filesystem.cloud’) 䞉䝣䜯䝃䞊䝗 䜏䛴䛛䜙䛺䛔䚹
  23. 23. Socialite (BETA) 6/12 䞉SNSㄆド䜢⾜䛖㏣ຍ䝟䝑䜿䞊䝆 2014/11/19᫬Ⅼ䛷β∧ 䞉ᑐᛂ䝃䞊䝡䝇 Facebook Github Google Twi`er 䞉䜲䞁䝇䝖䞊䝹 composer.json䛻௨ୗ䜢㏣ຍ䚹 laravel/socialite”: “2.0@dev”
  24. 24. Socialite (BETA) 6/12 䞉タᐃ config/services.php
  25. 25. Socialite (BETA) 6/12 䞉ᐇ⿦㻌䠄䛣䜣䛺ឤ䛨䠅㻌
  26. 26. Elixer 5/12 Laravel5䛻⤫ྜ䛥䜜䛯Web䜰䝉䝑䝖⟶⌮ᶵ⬟䠄gulp䝧䞊䝇䠅 node/npm/gulp䛾䜲䞁䝇䝖䞊䝹䛜ᚲせ Homestead(2.0?)䛻䛿䜲䞁䝇䝖䞊䝹῭䜏䛾䜘䛖䛰 䞉ᶵ⬟ 䜰䝉䝑䝖䛾䝁䞁䝟䜲䝹㻌㻸ess / Sass / CoffeeScript 䜰䝉䝑䝖䛾㐃⤖ CSS / JavaScript 䜰䝉䝑䝖䝣䜯䜲䝹䛾䝁䝢䞊 䜰䝉䝑䝖䝣䜯䜲䝹䛾䝞䞊䝆䝵䞁⟶⌮䠄Hash) Route / Event䛾䝇䜻䝱䞁 䝴䝙䝑䝖䝔䝇䝖䛾㉳ື㻌PHPUnit / PHPSpec 䞉ᣑᙇnode䝰䝆䝳䞊䝹 Stylus / Codecep0on / Browserify / Jade / Bower
  27. 27. New Environment Detec0on 8/12 [Laravel4] bootstrap/start.php 䛻グ㏙ 䝩䝇䝖ྡ䛛⎔ቃኚᩘ䛷ุᐃ䚹 $env = $app-detectEnvironment([ 'local' = [‘*'], ]); [Laravel5] .env䛻⎔ቃኚᩘ䛸䛧䛶ᣦᐃ䛩䜛䚹 .env䛿.gi0gnore䛻Ⓩ㘓䛥䜜䛶䛔䜛䚹 APP_ENV=local DB_USERNAME=dbuser DB_PASSWORD=dbpass 䝬䝅䞁ྡ䜔௵ព䛾⎔ቃኚᩘྡ䛷ᣦᐃ䛩䜛䛣䛸䛿䛷䛝䛺䛟䛺䛳䛯䠛䠛
  28. 28. Annota0on 9/12 • Laravel5䛷䛿Annota0on䛻䜘䜛ฎ⌮䜢ᢅ䛘䜛 䜘䛖䛻䟿 • Route䛻౑䛖ሙྜ • Event䛻౑䛖ሙྜ • doctrine/annota0ons䜢౑䛳䛶䜛䟿
  29. 29. Route Annota0on 9/12 • Controller䛾䝯䝋䝑䝗䛻Annota0on䜢䛴䛡䜛䛸Route䛸䛧䛶ᢅ䛖䛣䛸䛜ฟ᮶ 䜛䟿
  30. 30. Route Annota0on 9/12 • RouteServiceProvider.php䛻ᑐ㇟䛸䛺䜛䝁䞁䝖䝻䞊䝷ྡ䜢グ㏙
  31. 31. Route Annota0on 9/12 • Annota0on䜢グ㏙䛧䛯Controller䜢ㄞ䜏ྲྀ䛳 䛶䞉䞉䞉 • Route䜢⾲♧䛥䛫䛶䜏䜛䛸䞉䞉䞉
  32. 32. 9/12Route Annota0on
  33. 33. Event Annota0on 10/12 • Event䛻Annota0on䜢䛴䛡䜛䛸EventListener䛜Ⓩ㘓䛷䛝䜛䟿
  34. 34. 㻱vent Annota0on 10/12 • EventServiceProvider.php䛻ᑐ㇟䛸䛺䜛䝁䞁䝖䝻䞊䝷ྡ䜢グ㏙
  35. 35. Event Annota0on 10/12 • Annota0on䜢グ㏙䛧䛯Event䜢ㄞ䜏ྲྀ䛳䛶䞉䞉䞉 • 䝁䞁䝟䜲䝹䛥䜜䛯Event䜢☜ㄆ䛧䛶䜏䜛䛸䞉䞉䞉
  36. 36. 10/12Event Annota0on
  37. 37. Route Cache 11/12 • php ar0san route:cache䛷䝹䞊䝔䜱䞁䜾䛜 䜻䝱䝑䝅䝳ฟ᮶䜛䜘䛖䛻䛺䛳䛯䟿
  38. 38. Route Cache 11/12 • 䜻䝱䝑䝅䝳䛾๐㝖䛿php ar0san route:clear • 䛯䛰䛧䚸䜻䝱䝑䝅䝳䛧䛶䜒䛒䜎䜚䝟䝣䜷䞊䝬䞁䝇 ᨵၿ䛻䛿䛺䜙䛺䛔䛸䛔䛖ヰ䜒䞉䞉䞉
  39. 39. New File Generator 12/12 • Controller䜔䚸Ar0san Command䛾䜂䛺ᙧ䛜 make䝁䝬䞁䝗䛛䜙సᡂฟ᮶䜛䜘䛖䛻䛺䛳䛯䟿
  40. 40. New File Generator 12/12 Laravel4䛷᪤䛻䛒䛳䛯䝁䝬䞁䝗 • php ar0san make:console → php ar0san command:make • php ar0san make:controller → php ar0san controller:make • php ar0san make:migra0on → php ar0san migra0on:make
  41. 41. New File Generator 12/12 Laravel5䛷㏣ຍ䛥䜜䛯䝁䝬䞁䝗 • php ar0san make:middleware →Middleware䝕䜱䝺䜽䝖䝸䜈䛾䝣䜯䜲䝹䛾㏣ຍ
  42. 42. New File Generator 12/12 Laravel5䛷㏣ຍ䛥䜜䛯䝁䝬䞁䝗 • php ar0san make:provider →Providers䝕䜱䝺䜽䝖䝸䜈䛾䝣䜯䜲䝹䛾㏣ຍ
  43. 43. New File Generator 12/12 Laravel5䛷㏣ຍ䛥䜜䛯䝁䝬䞁䝗 • php ar0san make:request →Requests䝕䜱䝺䜽䝖䝸䜈䛾䝣䜯䜲䝹䛾㏣ຍ
  44. 44. Laravel5䛾䝸䝸䞊䝇䛿䞉䞉䞉 Symfony2.6䝸䝸䞊䝇ᚋ䠛 2015ᖺ1᭶䠛 ᪤Ꮡ䛾Laravel4䜰䝥䝸䛾⛣⾜䛿᫬ᮇᑦ᪩䛛䞉䞉䞉 ᪂つ䜰䝥䝸䜢䝥䝻䝖䝍䜲䝥ⓗ䛻స䜛䛺䜙 䝖䝷䜲䛩䜛౯್䛒䜚䟿
  45. 45. ஬཯⏣䝁䝽䞊䜻䞁䜾䝇䝨䞊䝇䛂VACANCY OFFICE䛃䛻䛶 ḟᅇ㻌2014ᖺ12᭶11᪥(ᮌ) 19:30ࠥ
  46. 46. [άືෆᐜ] ຮᙉ఍䞉䜲䝧䞁䝖㛤ദ Laravel Tokyo䛾Web䝃䜲䝖㛤Ⓨ 䠄䝕䝄䜲䞁䞉䝥䝻䜾䝷䝭䞁䜾䠅 ᭩⡠ᇳ➹ OctoberCMS◊✲䚸䛺䛹 [άືሙᡤ] 㒔ෆ䝁䝽䞊䜻䞁䜾䝇䝨䞊䝇䠄᭶2ᅇணᐃ䠅 Laravel Tokyo䝯䞁䝞䞊ເ㞟 contact@laravel.tokyo 䜎䛷㐃⤡䛟䛰䛥䛔䚹

×