P粉8521147522023-09-04 09:39:51
Your method is incorrect. In Laravel, the lifecycle of a request begins when the request arrives at the server and ends when the response is sent back to the user's browser. When you queue a job in Laravel, it means that the job will be processed later, maybe even on a different server. When the job actually runs, the original request life cycle has ended. Therefore, you cannot access request data within a queued job.
If you need to use the uploaded file in a queued job, you need to store the uploaded file in a location that the job can access. This can be your server's file system or a cloud storage service.
In your controller you have temporarily stored the file for processing with Excel:
$file = request()->file('file');
However, you do not persist the file, which is why the file is not available while the job is running. You need to store your files somewhere more permanent.
After storing the file permanently, you can read the file from the new location.