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

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

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

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

Yudai Shinnoki

September 13, 2017
Tweet

More Decks by Yudai Shinnoki

Other Decks in Programming

Transcript

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

    View full-size slide

  2. Yudai Shinnoki
    @konoki_nannoki
    Freelance Engineer
    ͓΋ͳҊ࣮݅੷
    PHPɺΠϯϑϥɺAndroid(Java)
    ษڧத
    SwiftɺReact Native
    ࠷ۙͷڵຯ
    Architecting on AWS
    21ສԁ+੫͸ϋʔυϧ͕ߴ͍…

    View full-size slide

  3. Brush-UPֶͼ
    •  LaravelΛ࢖ͬͨγεςϜΛ9/4ʹެ։͠·ͨ͠
    https://www.brush-up.jp

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  6. ൿ఻ͷλϨ
    •  PHP 5.3
    •  MySQL 5.1
    •  Smarty
    •  Shift-JISͱ૬ੑ͕ѱ͘ɺ{literal}Ͱ
    ғΘͳ͍ͱΤϥʔʹͳͬͨΓ͢Δ
    •  όʔδϣϯ؅ཧ͞Ε͍ͯͳ͍
    •  ͱ͜ΖͲ͜Ζʹྺ࢙Λײ͡ΒΕΔ
    •  CentOSͳͷʹ/user/local/apache2ͷ
    ઈରύε͕ϋʔυίʔυ͞ΕͯͨΓ͢Δ
    จࣈίʔυ͸Shift-JIS

    View full-size slide

  7. γεςϜߏ੒
    •  આಘͷ͠қ͔͞ΒɺLaravel 5.1 LTS Λબ୒
    •  PHP 7.0 (7.1͡Όͳ͍ཧ༝͸ಛʹແ͍)
    •  Laravel 5.5 LTS ͕ 8/30 ʹϦϦʔε
    •  طଘγεςϜ͔Βஈ֊తʹҠߦ
    •  nginxͰURL͝ͱʹϦόʔεϓϩΩγ
    •  DBεΩʔϚ͕มΘΔͱطଘγεςϜͷमਖ਼
    ΋ඞཁʹͳΔͷͰɺطଘγεςϜ͕ඞཁͳ͘
    ͳ͔ͬͯΒDBΛݟ௚͢

    View full-size slide

  8. ࣮૷্ͷ՝୊ ①
    طଘDBͱͷ࿈ܞ

    View full-size slide

  9. EloquentϞσϧͷ࣮૷
    •  protected $table
    •  ໋໊نଇʹԊ͍ͬͯͳ͍৔߹ඞਢ
    •  protected $primaryKey
    •  Model::whereΛ࢖͏͚ͩͩͬͨΒ࣮͸ෆཁ
    •  relationを考えると設定しておいたほうが無難
    •  const CREATED_AT, const UPDATED_AT
    •  ͲͪΒ΋ෆཁͳΒ public $timestamps = false;
    •  updateͷΈෆཁͳΒ
    public function setUpdatedAt($value) { }

    View full-size slide

  10. ෳ਺छྨͷEloquentϞσϧͰϧʔϓ͍ͨ͠
    •  Illuminate\Database\Eloquent\Collectionʹ
    ෳ਺classΛಥͬࠐΜͰ΋໰୊ͳ͍
    •  EloquentϞσϧʹڞ௨ͷΞΫηαʔΛ࣮૷͢Δ
    •  has-Oneͳؔ܎͕ଟஈʹͳ͍ͬͯΔ৔߹
    ҰஈʹͳΔΑ͏ʹΞΫηαʔͰΤΠϦΞε
    ͓ͯ͘͠ͱUndefined ErrorΛҙࣝ͠ͳ͍ͰࡁΉ

    View full-size slide

  11. ࣮૷্ͷ՝୊ ②
    Shift-JISରԠ

    View full-size slide

  12. /config/database.php ͷจࣈίʔυઃఆ
    •  DBͷจࣈίʔυΛແࢹͯ͠ ’charset’ => ’utf8’
    •  ͨͿΜ SET NAMES utf8 ͱಉ͡ޮՌ
    •  varcharͰ͸͏·͍͕͘͘blobͰจࣈԽ͚͢Δ
    •  ૉ௚ʹ’charset’ => ’sjis’
    •  ιʔε͸UTF8ʹ͍ͨ͠ͷͰɺ
    EloquentϞσϧ͔ΒAttributeऔಘ࣌ʹม׵
    •  Illuminate\Database\Eloquent\ModelΛ
    ܧঝͨ͠ abstract class SjisBaseModel
    Λ࣮૷ͯ͠ڞ௨ॲཧΛॻ͘ํ਑

    View full-size slide

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

    View full-size slide

  14. public function getAttribute($key) ͷ override
    •  ͢΂ͯͷΞΫηαʔʹڞ௨ͳॲཧΛॻ͚Δ
    •  ݸผʹΞΫηαʔ͕͋Δ৔߹ͦͷޙʹݺ͹ΕΔ
    •  getAttribute ʹSJIS->UTF8ม׵Λॻ͘৔߹
    getFooAttribute ͸SJISͰฦ͢ඞཁ͕͋Δ(ʂ)
    •  protected function getAttributeFromArray
    Λ override ͢Δ͜ͱͰDB͔Βऔಘͨ͠σʔλ
    ͷΈΛม׵Ͱ͖ͨ

    View full-size slide

  15. ݸਓతʹ
    ͍͍ͱײͨ͡ͱ͜Ζ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  18. ιʔείʔυ͕௥͍΍͍͢ʢؾ͕͢Δʣ
    •  PHPStorm Ͱߋʹշద
    •  ʮLaravelɹPHPStormʯͱ͔Ͱݕࡧ͢Δͱ
    ηοτΞοϓͷ৘ใ͕Ͱͯ͘Δ
    •  ܕએݴΛ࢖͏ͱΰϦΰϦͱิ׬ͯ͘͠ΕΔ
    •  ઌड़ͷgetAttributeFromArray ΋
    ͜ͷ͓ӄͰؾ͚ͮͨ

    View full-size slide

  19. ·ͱΊ
    •  ࣮૷্ͷ੍໿͕ଟ͍৔߹Ͱ΋ɺ
    LaravelͳΒॊೈʹରԠͰ͖Δͱײͨ͡
    •  DBͷݟ௚͠΋͍ͩͿָʹͳΓͦ͏
    •  Laravel 5.5 LTSҠߦʹ͍ͭͯͷ৘ใ͕
    ͋ͬͨΒڭ͍͑ͯͩ͘͞

    View full-size slide