Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

We-Ace's avatar
Level 1

Argument 1 passed to App\Exports\UserDataDownloadExport::__construct() must be of the type int, null given, called in /var/www/xvxv/app/Jobs/DownloadUserAccountCompleteData.php

I'm working on Laravel 7, and facing this issue. User can download their data, which we have collected. Need to pass user id to export class.

Argument 1 passed to App\Exports\UserDataDownloadExport::__construct() must be of the type int, null given, called in /var/www/xvxv/app/Jobs/DownloadUserAccountCompleteData.php on line 54 {"exception":"[object] (TypeError(code: 0): Argument 1 passed to App\\Exports\\UserDataDownloadExport::__construct() must be of the type int, null given, called in /var/www/xvxv/app/Jobs/DownloadUserAccountCompleteData.php on line 54 at /var/www/xvxv/app/Exports/UserDataDownloadExport.php:20

Controller

public function postdownloadRequestUserAccountData(){
		DownloadUserAccountCompleteData::dispatch(Auth::user());
		return back()->with('success','Your request is submitted, I will email you when process is completed');
	}

Job class

Export class

class UserDataDownloadExport implements WithMultipleSheets
{
    use Exportable;

    protected $userService;
    protected $menteeService;
    protected $trainingService;
    protected $authData;
    
    public function __construct($authData,UserService $userService,MenteeService $menteeService,TrainingService $trainingService)
    {
        $this->userService  = $userService;
        $this->menteeService  = $menteeService;
        $this->trainingService = $trainingService;
        $this->authData = $authData;
    }
    public function sheets(): array
    {
        $sheets = [];
        $sheets[] = new UserProfileExport($this->authData->id,$this->userService);
        return $sheets;
        
    }
}
0 likes
7 replies
Tray2's avatar

Your $authdata is null, that is why it's failing, make sure that you pass the correct value.

We-Ace's avatar
Level 1

@Tray2 Yes, you are right. But I tried by passing hard-coded id and Auth id as well.

public function postdownloadRequestUserAccountData(){
		DownloadUserAccountCompleteData::dispatch(Auth::user()->id);
		return back()->with('success','Your request is submitted, I will email you when process is completed');
	}

But the response is same, also not able Log the response.

Could you please help me in identifying what I'm missing.

jaseofspades88's avatar

If Auth::user() is null, then Auth::user()->id isn't going to work either, @We-Ace. You aren't passing an integer to a method that expects an integer. This isn't so cryptic.

1 like
jaseofspades88's avatar

What does 'it's not working' even mean, @We-Ace? Here's an idea... if you want help, help us help you.... 'it not working' is about as useful as me telling you 'it's raining here'.

Muhammad_Nawaz's avatar

It is because null is passed as the first argument to the UserDataDownloadExport class constructor, where an integer (the user ID) is expected. This typically happens when the authData property is not properly populated before it's used in the DownloadUserAccountCompleteData job. Auth Data Not Passed Correctly to the Job: Ensure that the authData is correctly passed when the job is dispatched. You're using Auth::user() in the controller, which should be returning the authenticated user. Verify that Auth::user() is returning a valid user object and not null.

In Controller public function postdownloadRequestUserAccountData(){ DownloadUserAccountCompleteData::dispatch(Auth::user()); return back()->with('success','Your request is submitted, I will email you when process is completed'); } If Auth::user() is null, it could be due to an issue with user authentication or a missing session. Confirm that the user is authenticated before dispatching the job. Check the Constructor in the Job Class: Ensure that the authData property is correctly set when the job is instantiated:

Job Class Constructor public function __construct($authData) { $this->authData = $authData; } The $authData object should contain the authenticated user's data, including the id.

Ensure Proper Dependency Injection in the Export Class: The UserDataDownloadExport class expects a user object ($authData) and service dependencies. Make sure that when the job handles the export, it passes the correct data.

Handling Job public function handle(UserService $userService, TrainingService $trainingService, MenteeService $menteeService, MailService $mailService) { $this->userService = $userService; $this->trainingService = $trainingService; $this->menteeService = $menteeService; $this->mailService = $mailService;

$name = $this->authData->id . '/yourdata.xlsx';
Excel::store(new UserDataDownloadExport(
    $this->authData,
    $this->userService,
    $this->menteeService,
    $this->trainingService
), $name, 'local');
...

} f $this->authData is null when the UserDataDownloadExport object is created, it will lead to the TypeError you mentioned. Before dispatching the job, dump the Auth::user() to ensure it is returning a valid user. dd(Auth::user());

martinbean's avatar

@we-ace Error messages don’t lie.

As multiple people have told you now, if you’re getting an error saying you’re passing null to something expecting int, then you’re passing null. If you’re passing Auth::id() and still getting the error then—guess what?—Auth::id() must be returning null as well!

This makes sense if you’re trying to call this in a queued job, because there isn’t a notion of an authenticated user in a CLI process such as a queued job.

So, if your job requires a user as part of the data, then you need to pass the current user instance to your job when queueing it:

SomeJob::dispatch(Auth::user(), $rest, $of, $your, $parameters);

And then reference that user property—instead of trying to get a user via the Auth facade—in your job’s handle method:

public function handle()
{
    $user = $this->user; // Will be user passed when job was dispatched
}

Please or to participate in this conversation.