-
composer.json
Open in GitHub{ // "require": { "php": "^7.3|^8.0", // "maatwebsite/excel": "^3.1" }, // }
-
app/Excel/Exports/UsersExport.php
Open in GitHubuse App\Models\User; use Illuminate\Contracts\View\View; use Maatwebsite\Excel\Concerns\FromView; class UsersExport implements FromView { public function view(): View { return view('exports.users', [ 'users' => User::where('type', User::Normal)->with('info')->whereRelation('info','companyId',companyId())->get() ]); } }
-
app/Http/Controllers/Manager/UserController.php
Open in GitHubuse App\Excel\Exports\UsersExport; use App\Http\Controllers\Controller; use Symfony\Component\HttpFoundation\BinaryFileResponse; class UserController extends Controller { // public function exportExcel(): BinaryFileResponse { return Excel::download(new UsersExport, 'users.xlsx'); } // }