What is the problem?
Laravel excel export problem
I have more than one table. How can i only using one model and controller to export the different tables contents? Route :
Route::get('export',function() { return view('export'); }); Route::get('exportTo/{type}', 'ExportController@index');
Model :
namespace App; use Illuminate\Database\Eloquent\Model;
class TestModel extends Model { protected $table = 'posts'; protected $fillable = ['title', 'content']; }
Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\ServiceProvider;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Excel;
use App\AccessModel;
class ExportController extends Controller {
public function index($type) {
>$data = AccessModel::get(['customer_name', 'company_name'])->toArray(); return Excel::create('Accesses Record', function ($excel) use ($data) { $excel->sheet('mySheet', function ($sheet) use ($data) { $sheet->fromArray($data); }); })->download($type);
Views:
` <div class="btn-group">
<a href="{{ url('exportTo/xls') }}">
<button class="btn btn-primary"><span class="glyphicon glyphicon-export"></span> Export
to xls
</button>
</a>
<a href="{{ url('exportTo/xlsx') }}">
<button class="btn btn-info"><span class="glyphicon glyphicon-export"></span> Export to
xlsx
</button>
</a>
<a href="{{ url('exportTo/csv') }}">
<button class="btn btn-warning"><span class="glyphicon glyphicon-export"></span> Export
to CSV
</button>
</a>
</div>`
Please or to participate in this conversation.