php - Export CSV/XLSX using Laravel 5.4 -


my post long pls me !

i tried export data database csv file, got 2 problems:

1. update: solved changing csv xlsx.

2. how can title_name in eloquent ? tried did not work.

$title_japan = titlejapan::select('id','name',$this->title->name)->get(); 

here titlejapan model:

    class titlejapan extends model {     public function title()     {         return $this->belongsto('app\title');     } } 

here title model:

    class title extends model {     public function titlejapan()     {         return $this->hasmany('app\titlejapan');     }  } 

and controller:

    class exportcontroller extends controller {     public function index()     {         return view('export.index');     }      public function exporttitlecsv()     {         $title = title::all();         $title_japan = titlejapan::select('id','name',$this->title->name)->get();          return excel::create('filename', function($excel) use ($title,$title_japan,$title_oversea) {              $excel->settitle('titlebandai');             $excel->sheet('firstsheet', function($sheet) use($title_japan) {                 $sheet->fromarray($title_japan);             });             $excel->sheet('secondsheet', function($sheet) use($title_oversea) {                 $sheet->fromarray($title_oversea);             });          })->export('csv');     } } 

file csv got

enter image description here

file csv want

enter image description here

a .csv file simple. it's data separated commas or other delimiter. therefore, cannot have multiple sheets. if export .xlsx should work.

for name of title, suggest eager load title , process result array.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -