外部委託の立場から半ば強引にLaravelを導入した話

 外部委託の立場から半ば強引にLaravelを導入した話

Laralab vol.1 (https://laralab.connpass.com/event/65160/) で発表させていただいた資料です。

C951afc0782b7d3d4800e25b4a4938a9?s=128

Yudai Shinnoki

September 13, 2017
Tweet

Transcript

  1. ֎෦ҕୗͷཱ৔͔Β ൒͹ڧҾʹLaravelΛಋೖͨ͠࿩ LaraLab vol.1 2017/09/13 @shibuya 21cafe

  2. Yudai Shinnoki @konoki_nannoki Freelance Engineer ͓΋ͳҊ࣮݅੷ PHPɺΠϯϑϥɺAndroid(Java) ษڧத SwiftɺReact Native

    ࠷ۙͷڵຯ Architecting on AWS 21ສԁ+੫͸ϋʔυϧ͕ߴ͍…
  3. Brush-UPֶͼ •  LaravelΛ࢖ͬͨγεςϜΛ9/4ʹެ։͠·ͨ͠ https://www.brush-up.jp

  4. ൿ఻ͷλϨ •  PHP 5.3 •  MySQL 5.1 •  Smarty

  5. ൿ఻ͷλϨ •  PHP 5.3 •  MySQL 5.1 •  Smarty • 

    Shift-JISͱ૬ੑ͕ѱ͘ɺ{literal}Ͱ ғΘͳ͍ͱΤϥʔʹͳͬͨΓ͢Δ จࣈίʔυ͸Shift-JIS
  6. ൿ఻ͷλϨ •  PHP 5.3 •  MySQL 5.1 •  Smarty • 

    Shift-JISͱ૬ੑ͕ѱ͘ɺ{literal}Ͱ ғΘͳ͍ͱΤϥʔʹͳͬͨΓ͢Δ •  όʔδϣϯ؅ཧ͞Ε͍ͯͳ͍ •  ͱ͜ΖͲ͜Ζʹྺ࢙Λײ͡ΒΕΔ •  CentOSͳͷʹ/user/local/apache2ͷ ઈରύε͕ϋʔυίʔυ͞ΕͯͨΓ͢Δ จࣈίʔυ͸Shift-JIS
  7. None
  8. γεςϜߏ੒ •  આಘͷ͠қ͔͞ΒɺLaravel 5.1 LTS Λબ୒ •  PHP 7.0 (7.1͡Όͳ͍ཧ༝͸ಛʹແ͍)

    •  Laravel 5.5 LTS ͕ 8/30 ʹϦϦʔε •  طଘγεςϜ͔Βஈ֊తʹҠߦ •  nginxͰURL͝ͱʹϦόʔεϓϩΩγ •  DBεΩʔϚ͕มΘΔͱطଘγεςϜͷमਖ਼ ΋ඞཁʹͳΔͷͰɺطଘγεςϜ͕ඞཁͳ͘ ͳ͔ͬͯΒDBΛݟ௚͢
  9. ࣮૷্ͷ՝୊ ① طଘDBͱͷ࿈ܞ

  10. EloquentϞσϧͷ࣮૷ •  protected $table •  ໋໊نଇʹԊ͍ͬͯͳ͍৔߹ඞਢ •  protected $primaryKey • 

    Model::whereΛ࢖͏͚ͩͩͬͨΒ࣮͸ෆཁ •  relationを考えると設定しておいたほうが無難 •  const CREATED_AT, const UPDATED_AT •  ͲͪΒ΋ෆཁͳΒ public $timestamps = false; •  updateͷΈෆཁͳΒ public function setUpdatedAt($value) { }
  11. ෳ਺छྨͷEloquentϞσϧͰϧʔϓ͍ͨ͠ •  Illuminate\Database\Eloquent\Collectionʹ ෳ਺classΛಥͬࠐΜͰ΋໰୊ͳ͍ •  EloquentϞσϧʹڞ௨ͷΞΫηαʔΛ࣮૷͢Δ •  has-Oneͳؔ܎͕ଟஈʹͳ͍ͬͯΔ৔߹ ҰஈʹͳΔΑ͏ʹΞΫηαʔͰΤΠϦΞε ͓ͯ͘͠ͱUndefined

    ErrorΛҙࣝ͠ͳ͍ͰࡁΉ
  12. ࣮૷্ͷ՝୊ ② Shift-JISରԠ

  13. /config/database.php ͷจࣈίʔυઃఆ •  DBͷจࣈίʔυΛແࢹͯ͠ ’charset’ => ’utf8’ •  ͨͿΜ SET

    NAMES utf8 ͱಉ͡ޮՌ •  varcharͰ͸͏·͍͕͘͘blobͰจࣈԽ͚͢Δ •  ૉ௚ʹ’charset’ => ’sjis’ •  ιʔε͸UTF8ʹ͍ͨ͠ͷͰɺ EloquentϞσϧ͔ΒAttributeऔಘ࣌ʹม׵ •  Illuminate\Database\Eloquent\ModelΛ ܧঝͨ͠ abstract class SjisBaseModel Λ࣮૷ͯ͠ڞ௨ॲཧΛॻ͘ํ਑
  14. None
  15. public function getAttribute($key) ͷ override •  ͢΂ͯͷΞΫηαʔʹڞ௨ͳॲཧΛॻ͚Δ •  ݸผʹΞΫηαʔ͕͋Δ৔߹ͦͷޙʹݺ͹ΕΔ • 

    getAttribute ʹSJIS->UTF8ม׵Λॻ͘৔߹ getFooAttribute ͸SJISͰฦ͢ඞཁ͕͋Δ(ʂ)
  16. public function getAttribute($key) ͷ override •  ͢΂ͯͷΞΫηαʔʹڞ௨ͳॲཧΛॻ͚Δ •  ݸผʹΞΫηαʔ͕͋Δ৔߹ͦͷޙʹݺ͹ΕΔ • 

    getAttribute ʹSJIS->UTF8ม׵Λॻ͘৔߹ getFooAttribute ͸SJISͰฦ͢ඞཁ͕͋Δ(ʂ) •  protected function getAttributeFromArray Λ override ͢Δ͜ͱͰDB͔Βऔಘͨ͠σʔλ ͷΈΛม׵Ͱ͖ͨ
  17. None
  18. ݸਓతʹ ͍͍ͱײͨ͡ͱ͜Ζ

  19. BladeʹૉͷPHPίʔυ͕ॻ͚Δ •  ࠔͬͨΒͱΓ͋͑ͣ<?php ?> Ͱॻ͚͹͍͍ •  ίϯϙʔωϯτͬΆ͘@include Ͱ͖Δ

  20. BladeʹૉͷPHPίʔυ͕ॻ͚Δ •  ࠔͬͨΒͱΓ͋͑ͣ<?php ?> Ͱॻ͚͹͍͍ •  ίϯϙʔωϯτͬΆ͘@include Ͱ͖Δ ͪΐͬͱෳࡶͳॲཧ ͉

    ςϯϓϨʔτ
  21. ιʔείʔυ͕௥͍΍͍͢ʢؾ͕͢Δʣ •  PHPStorm Ͱߋʹշద •  ʮLaravelɹPHPStormʯͱ͔Ͱݕࡧ͢Δͱ ηοτΞοϓͷ৘ใ͕Ͱͯ͘Δ •  ܕએݴΛ࢖͏ͱΰϦΰϦͱิ׬ͯ͘͠ΕΔ • 

    ઌड़ͷgetAttributeFromArray ΋ ͜ͷ͓ӄͰؾ͚ͮͨ
  22. ·ͱΊ •  ࣮૷্ͷ੍໿͕ଟ͍৔߹Ͱ΋ɺ LaravelͳΒॊೈʹରԠͰ͖Δͱײͨ͡ •  DBͷݟ௚͠΋͍ͩͿָʹͳΓͦ͏ •  Laravel 5.5 LTSҠߦʹ͍ͭͯͷ৘ใ͕

    ͋ͬͨΒڭ͍͑ͯͩ͘͞