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

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

kotamat
September 13, 2017

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

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

kotamat

September 13, 2017
Tweet

More Decks by kotamat

Other Decks in Programming

Transcript

  1. 

  2. 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ઃఆ͠ ͍ͨͱ͖ͱ͔ಛघͳϨεϙ ϯεʹ͍ͨ͠ͱ͖͸࢖͑Δ ͔ͳʝʁ
  3. #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
  4. $VTUPN7BMJEBUJPO3VMF όϦσʔγϣϯϧʔϧΛΫϥεԽͯ͠࠶ར༻Մೳʹ ˒˒˒˒ˑ w 3VMFΛ࣮૷ͨ͠Ϋϥε Λఆٛ͠ɺϧʔϧͷ஋ ʹΠϯελϯεΛ౉͢ ͚ͩͰϧʔϧઃஔͰ͖ Δ class

    CowbellValidationRule implements Rule { public function passes($attribute, $value) { return $value > 10; } public function message() { return ':attribute needs more cowbell!'; } } w ࣄۀυϝΠϯʹґଘ͠ ͨόϦσʔγϣϯ͸Α ͘࢖͍·Θ͢ͷͰ༗༻
  5. 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; });
  6. 1BDLBHF"VUP%JTDPWFSZ BQQQIQมߋ͠ͳͯ͘΋ύοέʔδ࢖͑Δ ˒˒˒˒˒ w ύοέʔδଆͰࠨهͷΑ͏ͳ ઃఆΛDPNQPTFSKTPOʹ ॻ͍͓͚ͯͩ͘Ͱɺউखʹొ ࿥͞ΕΔɻ w l'PPaa#BSa

    a4FSWJDF1SPWJEFSJT OPUGPVOEz஍ࠈ͔Β։์ ͞ΕΔɻɻʂ "extra": { "laravel": { "providers": [ "Foo\\Bar\\ServiceProvider" ], "aliases": { "Bar": "Foo\\Bar\\Facade" } } }
  7. 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');
  8. 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');
  9. &NBJM5IFNFTJO.BJMBCMFT ϝʔϧςϯϓϨʔτΛ؆୯ʹઃఆՄೳʹ ˒˒ˑˑˑ w .BJMBCMFͷΫϥεͰ UIFNFΛࢦఆͰ͖ΔΑ ͏ʹ w DPOGJH bNBSLEPXOQBUIT`

    <DPOGJH bNBSLEPXOUIFNF` > ʹࢦ ఆ͞ΕͨDTTΛಡΈࠐΉ w ෳ਺ͷαʔϏεΛ࣮ߦ class SendInvoice extends Mailable { protected $theme = 'my-theme'; ... }
  10. ·ͱΊ -BSBWFM͸։ൃޮ཰ˢͷόʔδϣϯ w ϩʔΧϧͰͷΈҙຯ͕͋ΔPS։ൃޮ཰্͛ΔΑ͏ͳΞοϓσʔ τ͕ओͩͬͨɻ w -BSBWFM͕XFC։ൃͷϑϨʔϜϫʔΫͷಓΛಥ͖ਐΜͰ͍Δҹ ৅ ͦ΋ͦ΋ͦ͏͍͏ཱͯ෇͚͚ͩͲ 

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