SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.28k stars 1.92k forks source link

[Bug]: The payload is invalid when export excel to laravel 7 #3990

Closed daviddprtma closed 1 year ago

daviddprtma commented 1 year ago

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

What version of Laravel Excel are you using?

^3.1

What version of Laravel are you using?

7.2.30

What version of PHP are you using?

7.3.31

Describe your issue

Hello when I want to export the file using maatwebsite excel package suddenly it appear with the error said that "the payload is invalid". The data that I want to export from the database is like first_name, last_name, username and email. I didn't want to store the password in my excel file while in my database it've been stored in there using hash password. So what should I do with this problem? I've been search the article to solve this problem also asking in stackoverflow, chatGPT but it didn't solve my prblem yet. So I wanna help from you team. And this is the screenshot that I got from laravel 7 using maatwebsite excel.

error export excel laravel 7

How can the issue be reproduced?

I think the issue comes when I do export excel using download method and in the export folder in UserExport.php. Here's my code in UserController.php public function export_excel() { return Excel::download(new UserExport, 'user.xlsx'); } And this is my UserExport.php <?php

namespace App\Exports;

use App\User; use Maatwebsite\Excel\Concerns\FromCollection;

class UserExport implements FromCollection { /**

What should be the expected behaviour?

My expected is when I click the button for Export Excel, it should be download automatically without any error for the future.

Tofandel commented 1 year ago

Please provide your model, you probably used a encrypted cast on the password, but this should not be the case, a hash is not an encrypted value and you can't retrieve it

daviddprtma commented 1 year ago

Please provide your model, you probably used a encrypted cast on the password, but this should not be the case, a hash is not an encrypted value and you can't retrieve it

Thank you for the reply. Well this is my model in User.php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable;

class User extends Authenticatable implements MustVerifyEmail { use Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'nama_depan', 'nama_belakang', 'nama_pengguna', 'email', 'password','nip','nis','roles'
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

/**
 * The attributes that should be cast to native types.
 *
 * @var array
 */
protected $casts = [
    'email_verified_at' => 'datetime',
];

public function guru($id)
{
    $guru = Guru::where('nip', $id)->first();
    return $guru;
}

public function siswa($id)
{
    $siswa = Siswa::where('nis', $id)->first();
    return $siswa;
}

I didn't use the encrypted password cast in model but I did that in my seeding database. Would it be the problem of the bug that I got it?

Tofandel commented 1 year ago

It also possible it comes from cookies because laravel encrypt's them and decrypts them, hard to say without a stack trace, but I doubt it has anything to do with this library, you should consider upgrading your laravel version, v7 is not an LTS and has been EOL for 2 years

Same for PHP, 7.3 is EOL, you should upgrade to 8.1