Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
daviddprtma opened this issue Sep 7, 2023 · 3 comments
Closed
1 task done

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

daviddprtma opened this issue Sep 7, 2023 · 3 comments
Labels

Comments

@daviddprtma
Copy link

daviddprtma commented Sep 7, 2023

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

  • Yes, it's still reproducable

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

get(); return $user; } } ### 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.
@daviddprtma daviddprtma added the bug label Sep 7, 2023
@Tofandel
Copy link
Contributor

Tofandel commented Sep 8, 2023

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
Copy link
Author

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants