Laravel 5.4执行php artisan make:job时--queued选项不存在求助
Hey there! Let's get this queued job issue sorted out for you. The problem here is pretty straightforward: Laravel 5.4 doesn't support the --queued option for the make:job command. That flag was added in later Laravel versions (around 5.5), so running that command in 5.4 will throw the error you're seeing.
Here's how you can create a queued job correctly in Laravel 5.4:
Create the job without the
--queuedflag
Run this command in your terminal instead:php artisan make:job SendSMSMessagesThis will generate a new job file at
app/Jobs/SendSMSMessages.php.Ensure the job implements the
ShouldQueueinterface
Open the generatedSendSMSMessages.phpfile. By default, Laravel 5.4 might already include this, but double-check to be sure. Your class should look something like this:namespace App\Jobs; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; class SendSMSMessages implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; // Your job initialization logic public function __construct() { // } // The core logic of your SMS sending job public function handle() { // Add your SMS sending code here } }- If
implements ShouldQueueis missing, add it to the class declaration. - Make sure the
use Illuminate\Contracts\Queue\ShouldQueue;import is present at the top of the file.
- If
Verify your queue setup
Don't forget to configure your queue driver in.env(e.g.,QUEUE_DRIVER=databaseorQUEUE_DRIVER=redis) and start the queue worker with one of these commands:# Listens for queue jobs and restarts automatically when code changes php artisan queue:listen # Processes queue jobs more efficiently, requires a restart after code changes php artisan queue:work
That's it! Your SendSMSMessages job will now be processed asynchronously via Laravel's queue system.
内容的提问来源于stack exchange,提问作者HItesh Tank

