Advertisement
OHIDUL951

The artisan file

May 11th, 2016
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1.  
  2.     protected $signature = 'import:excelfile';
  3.     protected $description = 'This imports an excel file';
  4.  
  5.  
  6.     public function __construct()
  7.     {
  8.         parent::__construct();
  9.     }
  10.  
  11.     public function handle()
  12.     {
  13.         $file = Flag::where('imported', '=', '0')->orderBy('created_at', 'DESC')->first();
  14.  
  15.         $file_path = 'public/files/' . $file->file_name;
  16.  
  17.         Excel::load($file_path, function($reader) {
  18.             $reader->each(function($sheet) {
  19.                 foreach($sheet->toArray() as $row) {
  20.                     RealState::firstOrCreate($sheet->toArray());
  21.                 }
  22.             });
  23.         });
  24.  
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement