0

I recently just got stuck with this problem. Exporting my database data to excel using Laravel Excel. I just copied the code on the tutorial links, but unfortunately it doesn't work on me. And I think I got everything setted up for laravel excel configuration.Can you help me solve this? Thanks. Here are my codes.

my controller method

public function exportInventory(){

    $products = Product::all();

    Excel::create('products', function($excel) use($products){

    $excel->sheet('Excel sheet', function($sheet) use($products){

      $sheet->fromArray($products);
      $sheet->setOrientation('landscape');

    });

    })->export('xls');

}

My Model

<?php

 namespace App\Product;

 use Illuminate\Database\Eloquent\Model;

 class Product extends Model
 {

//
   protected $fillable =   ['pharmaceutical','description','unit','quantity','price','amount','type','packaging','lot','expiry_date_month'];
   protected $guarded = ['price'];
 }

My Database Table

enter image description here

Error enter image description here

3
  • And which one is line 76 in your ProductController ? Commented Apr 9, 2016 at 10:11
  • it points out the })->export('xls'); Commented Apr 9, 2016 at 10:17
  • Please help me with this... Commented Apr 9, 2016 at 11:17

1 Answer 1

1

Change your code : $products = Product::all(); to $products = Product::all()->toArray();

Sign up to request clarification or add additional context in comments.

1 Comment

Did it helped you?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.