I would like to export an Excel file from a blade Laravel view using Laravel Excel but I got this error:
Declaration of App\Http\Controllers\ExportController::view($id): Illuminate\Contracts\View\View must be compatible with Maatwebsite\Excel\Concerns\FromView::view(): Illuminate\Contracts\View\View
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use App\User;
class ExportController implements FromView
{
public function view($id): View
{
return view('users.export', [
'user' => User::find($id)
]);
}
}
Route
Route::get('exportxls/{id}', 'ExportController@view');
Blade File
<table>My data is here...</table>
What is wrong ?