Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Laravel5.5のアプデ内容を勝手に評価してみた

2b061d517e360c493bb567aa6c3e540d?s=47 kotamat
September 13, 2017

 Laravel5.5のアプデ内容を勝手に評価してみた

2017-09-13開催されたLaralab vol.1 https://laralab.connpass.com/event/65160 の発表内容です

2b061d517e360c493bb567aa6c3e540d?s=128

kotamat

September 13, 2017
Tweet

More Decks by kotamat

Other Decks in Programming

Transcript

  1.  -BSBWFMͷ Ξϓσ಺༰Λউख ʹධՁͯ͠Έͨ  !LPUBNBU

  2.  ࣗݾ঺հ

  3.  ࣗݾ঺հ দຊ޺ଠ ·ͭ΋ͱ͜͏ͨ  גࣜձࣾ4$065&3$50 ۀ຿ͷόοΫΤϯυ͸΄΅-BSBWFM ࣗసं͕޷͖ !LPUBNBU

  4. ʗ ʗ స৬ر๬ͷ༑ਓ஌ਓΛ اۀʹ঺հ͠ใुΛಘΒΕΔ $UP#ਓࡐ঺հαʔϏε 4$065&3ͱ͸

  5. ༗ྉ৬ۀ঺հ ਓࡐ঺հձࣾ
 ϔουϋϯλʔ اۀ ٻ ৬ ऀ ༗ྉ৬ۀ঺հ ঺հͯ͠ใुΛಘΔʹ͸໔ڐ͕ඞཁ ʹ

  6. 4$065&3ͱ͸ ا ۀ స ৬ ऀ εΧ΢λʔ
 ొ࿥ऀ ݸਓ͕঺հͯ͠ใुΛड͚औΕΔ ʹ

  7. ཧղͷ͋Δ૬ஊ૬ख ࣌ؒΛ͔͚ͨҙࢥܾఆ͕Ͱ͖Δ ࠷దͳٻਓΛબͼԠืͰ͖Δ ࠷΋స৬ऀʹدΓఴͬͨ঺հΛ࣮ݱ 4$065&3ͷར఺ 4$065&3ͷಛ௃

  8. 

  9. 

  10. ಺༰ Ξοϓσʔτͷ಺༰ΛউखʹධՁ w ධՁ࣠ w ͓ͬײ w ࣮༻ੑ w ˑ˒ͰධՁ

  11. 3FTQPOTBCMF ϨεϙϯεΛΫϥεԽͯ͠ఆٛͰ͖Δ ˒˒˒˒ˑ use Illuminate\Contracts\Support\Responsable; class ExampleObject implements Responsable {

    public function __construct($name = null) { $this->name = $name ?? 'Teapot'; } public function status() { switch(strtolower($this->name)) { case 'teapot': return 418; default: return 200; } } public function toResponse() { return response( "Hello {$this->name}", $this->status(), ['X-Person' => $this->name] ); } } w UP3FTQPOTFΛ࣮૷͠ ͨ3FTQPOTBCMFܕΛฦ Γ஋ʹ͢Δ͜ͱͰɺ೚ҙͷ ϨεϙϯεΛ࣮ݱͰ͖Δɻ w "1*͝ͱʹWJTJCMFઃఆ͠ ͍ͨͱ͖ͱ͔ಛघͳϨεϙ ϯεʹ͍ͨ͠ͱ͖͸࢖͑Δ ͔ͳʝʁ
  12. #MBEFJG #MBEFͷ!ؔ਺ΛಠࣗఆٛͰ͖Δ ˒˒ˑˑˑ w #MBEFJG Λ 4FSWJDF1SPWJEFSCPP U Ͱఆ͓͚ٛͯͩ͘͠Ͱ࢖ ༻Մೳ

    w !ؔ਺͸CMBEFͰ࢖༻Մೳ w 1PMJDZͱͷซ༻Ͱ৭ʑ޿͕ Γͦ͏ɻɻʁ w CMBEF࢖ͬͯͳ͍ͱ͍Βͳ͍  use Illuminate\Support\Facades\Blade; Blade::if('admin', function () { return auth()->check() && auth()- >user()->isAdmin(); }); @admin <a href="{{ route('super.secret') }}">Secret Page</a> @else Welcome Guest. <a href="{{ route('login') }}">Login</a> @endadmin
  13. $VTUPN7BMJEBUJPO3VMF όϦσʔγϣϯϧʔϧΛΫϥεԽͯ͠࠶ར༻Մೳʹ ˒˒˒˒ˑ w 3VMFΛ࣮૷ͨ͠Ϋϥε Λఆٛ͠ɺϧʔϧͷ஋ ʹΠϯελϯεΛ౉͢ ͚ͩͰϧʔϧઃஔͰ͖ Δ class

    CowbellValidationRule implements Rule { public function passes($attribute, $value) { return $value > 10; } public function message() { return ':attribute needs more cowbell!'; } } w ࣄۀυϝΠϯʹґଘ͠ ͨόϦσʔγϣϯ͸Α ͘࢖͍·Θ͢ͷͰ༗༻
  14. EVNQDPMMFDUJPO DPMMFDUJPOͷϝιουνΣʔϯͷ్தͰத਎ΈΕΔΑ͏ʹ ˒ˑˑˑˑ w ίϨΫγϣϯͷ్தͰ EVNQ ೖΕΕ͹ͦͷ్த Λඪ४ग़ྗ͢Δ w EE

    ͩͱFYJUͱͳΔ w ։ൃதͩͱ݁ߏ࢖͏͔΋͠Ε ͳ͍͕ɺMBSBWFMUJOLFSͰ ͍ͩͿࣄ଍Γͦ͏ɻɻ collect([1,2,3])->map(function($i){ return $i * 2; })->dump()->reject(function($i){ return $i < 3; });
  15. 1BDLBHF"VUP%JTDPWFSZ BQQQIQมߋ͠ͳͯ͘΋ύοέʔδ࢖͑Δ ˒˒˒˒˒ w ύοέʔδଆͰࠨهͷΑ͏ͳ ઃఆΛDPNQPTFSKTPOʹ ॻ͍͓͚ͯͩ͘Ͱɺউखʹొ ࿥͞ΕΔɻ w l'PPaa#BSa

    a4FSWJDF1SPWJEFSJT OPUGPVOEz஍ࠈ͔Β։์ ͞ΕΔɻɻʂ "extra": { "laravel": { "providers": [ "Foo\\Bar\\ServiceProvider" ], "aliases": { "Bar": "Foo\\Bar\\Facade" } } }
  16. 8IPPQT ؼ͖ͬͯͨ8IPPQT ˒˒˒˒˒ w ΤϥʔϋϯυϦϯάΛ͖Ε͍ ʹදࣔ w *%&༻ʹϦϑΝϨϯεΛදࣔ w ग़ྗϑΥʔϚοτΛબ୒Ͱ͖

    Δ +40/ 9.- 40"1  w ֦ு͕༰қ
  17. UISPX@JGIFMQFS CPPM൑ఆͰྫ֎౤͛Δϔϧύʔ ˒˒˒˒ˑ w ΄΅λΠτϧ௨ΓͰ͆͢ w &YDFQUJPO)BOEMFSͰϨ εϙϯεఆ͍ٛͯ͠Δ৔߹͸ ࢖͑Δ͔΋ $foo

    = true; throw_if($foo, new BarException('Foo is true')); // or throw_if($foo, BarException::class, 'Foo is true');
  18. 7BMJEBUJPOSFUVSOTSFRVFTUEBUB 7BMJEBUJPOͰఆٛͨ͠ϑΟʔϧυzͷΈzσʔλநग़ͯ͠ ฦ͢ ˒˒˒˒˒ w SFRVFTU POMZ Λ࢖ Θͳͯ͘Α͘ͳͬͨɻ w

    όϦσʔγϣϯϧʔϧແ͠Ͱ σʔλΛड͚औΓ͍ͨ৔߹͸ ۭจࣈͰϧʔϧΛࢦఆ͢Δɻ w ؔ৺͕ڽॖ͞ΕΔͷͰ $data = $this->validate(request(), [ 'name' => 'required', 'price' => 'required|numeric', 'notRequiredField' => '', ]); // $data = request()->only('name', 'price', 'category_id');
  19. 'SPOUFOEQSFTFUT BSUJTBOίϚϯυͰKTϑϨʔϜϫʔΫ؆୯ઃஔ ˒ˑˑˑˑ w 3FBDU CPPUTUSBQ  7VFKTΛઃஔͰ͖ΔΑ͏ʹ w ਖ਼௚࠷ॳ͔͠࢖Θͳ͍ʝ

    php artisan preset react|bootstrap
  20. .JHSBUF'SFTI$PNNBOE શςʔϒϧΛ%SPQ͔ͯ͠ΒϚΠάϨʔγϣϯ࣮ߦ ˒˒˒˒˒ w SFGSFTIͱ͸ҧ͍ϩʔϧ όοΫ͠ͳ͍ͷͰɺݱঢ়ͷ%# ঢ়گ೗ԿʹΑͬͯϚΠάϨʔ γϣϯ͕ࣦഊ͠ͳ͍ w ຊ൪%#ΛϛϥʔϦϯάͯ͠

    εςʔδϯά%#Λ࢖͍ͬͯ ΔϓϩδΣΫτͰ͸༗༻ php artisan migrate:fresh
  21. &NBJM5IFNFTJO.BJMBCMFT ϝʔϧςϯϓϨʔτΛ؆୯ʹઃఆՄೳʹ ˒˒ˑˑˑ w .BJMBCMFͷΫϥεͰ UIFNFΛࢦఆͰ͖ΔΑ ͏ʹ w DPOGJH bNBSLEPXOQBUIT`

    <DPOGJH bNBSLEPXOUIFNF` > ʹࢦ ఆ͞ΕͨDTTΛಡΈࠐΉ w ෳ਺ͷαʔϏεΛ࣮ߦ class SendInvoice extends Mailable { protected $theme = 'my-theme'; ... }
  22. .BJMBCMFTSFOEFSUPCSPXTFS ϝʔϧจ໘Λϒϥ΢βͰ֬ೝͰ͖ΔΑ͏ʹ ˒˒˒˒˒ w 3FOEFSBCMFΛܧঝͨ͠Ϋϥε Ͱ͋Ε͹ɺϨεϙϯεʹΠϯελ ϯε౉͚ͩ͢Ͱϒϥ΢βνΣοΫ Մೳʹ w ࠓ·Ͱ͸NBJMDBUDIFSͳͲͰ

    ϝʔϧඈ͹ͨ͠Γ͍ͯͨ͠ͷͰɺ σβΠϯमਖ਼͸͍ͩͿָʹ Route::get('/demo', function () { return new App\Mail\UserWelcome(); });
  23. WFOEPSQVCMJTI1SPWJEFSQSPNQU WFOEPSQVCMJTI࣮ߦ࣌࢖༻͢Δ1SPWJEFSΛબ୒͢Δ Α͏ʹ ˒˒ˑˑˑ w WFOEPSQVCMJTI࣮ߦ࣌શ෦ QVCMJTI͞ΕΔͷΛ๷͙ w ։ൃ࣌ϓϥάΠϯͷνΣοΫͰ͸ ࢖͑Δͱࢥ͏͚Ͳɺ࣮ӡ༻࣌͸

    UBHIPHFͰࢦఆ͢ΔͷͰɺͦΕ ΄ͲԸܙ͸ͳ͍͔ͳ͊ɻɻ
  24. NBLJOH.PEFM'BDUPSZ NPEFMGBDUPSZΛBSUJTBOίϚϯυͰੜ੒Մೳʹ ˒ˑˑˑˑ w ίϚϯυҰൃͰNPEFMGBDUPSZ ͕ੜ੒Մೳ w ͨͩɺੜ੒͞ΕΔͷ͕ɺۭͷ΋ͷ ͳͷͰɺਖ਼௚SZNBOBMV GBDUPSZHFOFSBUPSͰ.PEFM

    ͷGJMMBCMFΛ൑ఆͯࣗ͠ಈੜ੒ ͢Δ΄͏͕࢖͍উख͕͍͍ɻɻ php artisan make:factory UserFactory
  25. ·ͱΊ -BSBWFM͸։ൃޮ཰ˢͷόʔδϣϯ w ϩʔΧϧͰͷΈҙຯ͕͋ΔPS։ൃޮ཰্͛ΔΑ͏ͳΞοϓσʔ τ͕ओͩͬͨɻ w -BSBWFM͕XFC։ൃͷϑϨʔϜϫʔΫͷಓΛಥ͖ਐΜͰ͍Δҹ ৅ ͦ΋ͦ΋ͦ͏͍͏ཱͯ෇͚͚ͩͲ 

    w ٕज़తʹഁյతʹ໘ന͍Ξοϓσʔτͱݴ͏ײ͡Ͱ͸ͳ͔ͬͨʝ w -54خ͍͠ DPNQPTFSDSFBUFMBSBWFMMBSBWFM QIQBSUJTBOTFSWF ૣ଎࢖ͬͯΈΑ͏