skip to Main Content

when i run the laravel schedule comman, "php artisan schedule:work "i get this error. am running;
laravel 11
php 8.3


   ArgumentCountError 

  Too few arguments to function AppJobsOrangeJob::__construct(), 0 passed in D:projectspulseroutesconsole.php on line 8 and exactly 1 expected

  at appJobsOrangeJob.php:20
     16▕ {
     17▕     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
     18▕     public $tries = 3;
     19▕     public  $orange;
  ➜  20▕     public function __construct( $orange )
     21▕     {
     22▕         $this->orange=$orange;
     23▕     }
     24▕

  1   routesconsole.php:8
      AppJobsOrangeJob::__construct()
  2   vendorlaravelframeworksrcIlluminateFoundationConsoleKernel.php:499

don’t know why i get that error.

here is my controller from where am dispatching the job

    public function index()
    {
        $oranges = DB::connection('connectpay')
            ->table('oranges')
            ->whereYear('created_at', '=', date('Y'))
            ->where('created_at', '<', Carbon::now()->subMinutes(1)->toDateTimeString())
            ->where('status', '=', 'pending')->get();

        foreach ($oranges as $orange) {
            OrangeJob::dispatch($orange);
        }
    }

my laravel’s job class

<?php

namespace AppJobs;

use AppModelsTest;
use CarbonCarbon;
use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use IlluminateQueueInteractsWithQueue;
use IlluminateQueueSerializesModels;
use IlluminateSupportFacadesDB;
use function LaravelPromptstable;

class OrangeJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    public $tries = 3;
    public  $orange;
    public function __construct( $orange )
    {
        $this->orange=$orange;
    }

    public function handle():void
    {
    
       $orange= $this->orange;
        //        we check our transactions status
        $this->checkOrangeTransactions($orange);
    }

here is my routes/console file where i want to chedule the job

<?php

use AppJobsOrangeJob;



Schedule::job(new OrangeJob())->everySecond();

thank in advance

2

Answers


  1. In this please pass some arguments to OrangeJob()

    Schedule::job(new OrangeJob())->everySecond();
    

    Modified code will be like:

    $someArgument = "some data or dataset";
    Schedule::job(new OrangeJob($someArgument))->everySecond();
    
    Login or Signup to reply.
  2. OrangeJob is expecting parameter. when dispatching the the parameters not passing via OrangeJob.

    $orange = [
       id: "ewdsdmsmd",
       user_id : 2
    ];
    
    Schedule::job(new OrangeJob($orange))->everySecond();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search