Laravel-excel: how to export file from db in csv..

Created on 18 Mar 2015  路  4Comments  路  Source: Maatwebsite/Laravel-Excel

I have installed the package but don't know how to export so plz help

Most helpful comment

In my database I have a table prices
table

I therefore created a model Price with php artisan make:model Price and set the $table property as well as the $fillable property on the model:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Price extends Model {

    //
    protected $table = "prices";

    protected $fillable = ['*']; 

}

Now for a quick check I used the root route:

Route::get('/', function()
{
    Excel::create('Filename', function($excel) {
        $excel->sheet('Sheetname', function($sheet) {
            $prices = \App\Price::all();
            $sheet->fromModel($prices);
        });
    })->download('xls');
});

I then get the Excel file presenten when visiting the URL with my browser:
file

All 4 comments

In my database I have a table prices
table

I therefore created a model Price with php artisan make:model Price and set the $table property as well as the $fillable property on the model:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Price extends Model {

    //
    protected $table = "prices";

    protected $fillable = ['*']; 

}

Now for a quick check I used the root route:

Route::get('/', function()
{
    Excel::create('Filename', function($excel) {
        $excel->sheet('Sheetname', function($sheet) {
            $prices = \App\Price::all();
            $sheet->fromModel($prices);
        });
    })->download('xls');
});

I then get the Excel file presenten when visiting the URL with my browser:
file

Check the docs about exporting as well: http://www.maatwebsite.nl/laravel-excel/docs/export

Oh yeah forgot that link.

Thanks for your help with the support btw, I appreciate it :)

Was this page helpful?
0 / 5 - 0 ratings