I’d like to have user’s download center in my laravel application
Hence , i need to add the user information for each job batches,
The simplest thoughts in my mind is to add the user_id column on the job_batches table
however it seems that the job_batches table will be updated under the hood by laravel itself when the job dispatched
If using the above approach, i need to “interrupt” the laravel insert process by adding the user_id, but i don’t know how to do that
How can I achieve this ? or maybe there is more suitable way to do it rather than interrupting laravel’s default process
9
you can fetch user informations from payload of the job, when you dispatch new job send $user
in constructor
class YourDownloadJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*/
public function __construct(
public User $user
) {}
/**
* Execute the job.
*/
public function handle(): void
{
// Process download here with $user info
}
}
and when you want to dispatch this job
$user = User::find(1);
YourDownloadJob::dispatch($user)
Ziad B. Almargih is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1