Category: Laravel
Are you looking for import and export Excel files in Laravel? In the real world, sometimes we want to export records from the application.
In this article, we study exporting and importing Excel files in your Laravel application.
public function export() { return (new FastExcel(User::all()))->download('users.xlsx', function ($user) { return [ 'Name' => $user->name, 'Email' => $user->email, ]; }); }
public function import(Request $request) { $users = (new FastExcel)->import($request->file('users'), function ($line) { return User::create([ 'name' => $line['Name'], 'email' => $line['Email']]); }); return redirect('excel')->with(['success' => "Users imported successfully."]); }