Your $authdata is null, that is why it's failing, make sure that you pass the correct value.
Aug 27, 2024
7
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
class DownloadUserAccountCompleteData implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $authData;
protected $userService;
protected $trainingService;
protected $menteeService;
protected $mailService;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($authData)
{
$this->authData = $authData;
}
/**
* Execute the job.
*
* @return void
*/
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');
$zip = new ZipArchive();
$fileName = 'yourdata_'.time().'.zip';
//Save Download Request
$this->userService->dataDownloadRequest($this->authData->id,$fileName);
$folderPath = storage_path('app/'.$this->authData->id);
try {
File::makeDirectory($folderPath, 0777, true, true);
Log::info('Folder created successfully at: ' . $folderPath);
} catch (\Exception $e) {
Log::error('Failed to create folder: ' . $e->getMessage());
}
if ($zip->open(storage_path($fileName), \ZipArchive::CREATE)== TRUE)
{
$files = File::files(storage_path('app/'.$this->authData->id));
foreach ($files as $key => $value){
$relativeName = basename($value);
$zip->addFile($value, $relativeName);
}
$zip->close();
}
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;
}
}
Please or to participate in this conversation.