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

LaraCSVで手軽にCSVを出力する/Easily generate CSV by Lar...

kkznch
May 16, 2019

LaraCSVで手軽にCSVを出力する/Easily generate CSV by LaraCSV

Laravel Meetup宮崎
登壇枠で使用

参考URL
https://re-build.connpass.com/event/129466/

kkznch

May 16, 2019
Tweet

More Decks by kkznch

Other Decks in Technology

Transcript

  1. CSVͷϏϧυ // ΠϯελϯεΛੜ੒͢Δ $csvExporter = new \Laracsv\Export(); // ୈҰҾ਺ʹCollectionΛɺ //

    ୈೋҾ਺ʹCSVͰग़ྗ͍ͨ͠ϞσϧͷΧϥϜ໊Λೖྗ͢Δ $csvExporter->build(Users::get(), ['email', 'name']);
  2. ஋ͷ௥Ճɾมߋ͕Ͱ͖Δ $csvExporter->beforeEach(function($user) { // طଘͷ஋Λ্ॻ͖Ͱ͖Δ $user->email = '[email protected]'; // ଘࡏ͠ͳ͍஋Λ௥ՃͰ͖Δ

    $user->note = $user->name . 'ϝϞͰ͢'; }); $csvExporter->build(User::get(), [‘email', 'name', ‘note'])->download(); email,name,note [email protected],"Ԭ෦ ྙଠ࿠","Ԭ෦ ྙଠ࿠ϝϞͰ͢" [email protected],"௣໊ ·ΏΓ","௣໊ ·ΏΓϝϞͰ͢"
  3. ݁Ռ ࣌ؒʢඵʣ ίϝϯτ MBSBDTW  ଎౓͸஗͍͕࢖͍উख͸Α͍ FYDFM  ग़ྗ͢ΔͨΊʹ&YQPSU༻ΫϥεΛ ༻ҙ͢Δඞཁ͕͋ͬͯ໘౗͍͘͞

    MBSBWFMGPSNBUUFS  ϑΥʔϚοτͷม׵͚ͩߦΘΕΔɻ ϑΝΠϧ΁ͷॻ͖ग़͠͸ཁࣗ࡞ GBTUFYDFM  ଌఆϛεͬͨͷ͔ͳʜ ϫϯϥΠφʔͰ$47ര଎ग़ྗ͸૲