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

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

Laravel Meetup宮崎
登壇枠で使用

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

0451a8e214a5c0ddffd489528adbf787?s=128

kkznch

May 16, 2019
Tweet

Transcript

  1. 4.
  2. 5.
  3. 8.

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

    ୈೋҾ਺ʹCSVͰग़ྗ͍ͨ͠ϞσϧͷΧϥϜ໊Λೖྗ͢Δ $csvExporter->build(Users::get(), ['email', 'name']);
  4. 12.

    ஋ͷ௥Ճɾมߋ͕Ͱ͖Δ $csvExporter->beforeEach(function($user) { // طଘͷ஋Λ্ॻ͖Ͱ͖Δ $user->email = 'hoge@piyo.com'; // ଘࡏ͠ͳ͍஋Λ௥ՃͰ͖Δ

    $user->note = $user->name . 'ϝϞͰ͢'; }); $csvExporter->build(User::get(), [‘email', 'name', ‘note'])->download(); email,name,note hoge@piyo.com,"Ԭ෦ ྙଠ࿠","Ԭ෦ ྙଠ࿠ϝϞͰ͢" hoge@piyo.com,"௣໊ ·ΏΓ","௣໊ ·ΏΓϝϞͰ͢"
  5. 21.

    ݁Ռ ࣌ؒʢඵʣ ίϝϯτ MBSBDTW  ଎౓͸஗͍͕࢖͍উख͸Α͍ FYDFM  ग़ྗ͢ΔͨΊʹ&YQPSU༻ΫϥεΛ ༻ҙ͢Δඞཁ͕͋ͬͯ໘౗͍͘͞

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