Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

workizzy's avatar

making database query in queue jobs

Okay profs,

I'm trying to create a count downtime for individual by which a specific task will be shuffled to another person. so I am trying to use laravel queue.

My problem: I can't use models in queue jobs to update the databae and shuffle roles for user after the specified time.

public function handle()
    {
            // $check = new ZoommerActivities;
            // $check->where()
        $check = ZoomsActivities::where('trace_id', $this->trace_id)->first();
        if($check->complete == 0){
            $canceloffer = ZoomsActivities::where('trace_id', $this->trace_id)->update(['incomplete' => 1]);
            if($canceloffer == 1){
                $returnOfferToTable = ZoomsRequest::where('trace_id', $this->trace_id)->update(['accept' => 0]);
            }
            
        }
    }
0 likes
15 replies
Sinnbeck's avatar

Why not? And please format your code (there is a link to the help file when you edit the post)

workizzy's avatar

@Sinnbeck

Okay. The error I got from the failed_jobs database is this.

Error: Class 'App\Jobs\ZoommerActivities' not found in C:\wamp64\www\zoommit_v2\app\Jobs\ValidatePickUp.php:39
Stack trace:
#0 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(36): App\Jobs\ValidatePickUp->handle()
#1 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#2 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#3 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#4 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\Container.php(651): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#5 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(128): Illuminate\Container\Container->call(Array)
#6 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}(Object(App\Jobs\ValidatePickUp))
#7 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\ValidatePickUp))
#8 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Bus\Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#9 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(120): Illuminate\Bus\Dispatcher->dispatchNow(Object(App\Jobs\ValidatePickUp), false)
#10 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}(Object(App\Jobs\ValidatePickUp))
#11 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(App\Jobs\ValidatePickUp))
#12 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#13 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\Queue\Jobs\DatabaseJob), Object(App\Jobs\ValidatePickUp))
#14 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(98): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#15 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(428): Illuminate\Queue\Jobs\Job->fire()
#16 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(378): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#17 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(172): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#18 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(117): Illuminate\Queue\Worker->daemon('database', 'default', Object(Illuminate\Queue\WorkerOptions))
#19 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(101): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'default')
#20 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(36): Illuminate\Queue\Console\WorkCommand->handle()
#21 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#22 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure(Object(Closure))
#23 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#24 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Container\Container.php(651): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#25 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Console\Command.php(136): Illuminate\Container\Container->call(Array)
#26 C:\wamp64\www\zoommit_v2\vendor\symfony\console\Command\Command.php(299): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#27 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Console\Command.php(121): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#28 C:\wamp64\www\zoommit_v2\vendor\symfony\console\Application.php(978): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#29 C:\wamp64\www\zoommit_v2\vendor\symfony\console\Application.php(295): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#30 C:\wamp64\www\zoommit_v2\vendor\symfony\console\Application.php(167): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#31 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Console\Application.php(92): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#32 C:\wamp64\www\zoommit_v2\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(129): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#33 C:\wamp64\www\zoommit_v2\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#34 {main}
Sinnbeck's avatar

@workizzy you need to import the models at the top of the file

For instance

use App\Models\ZoomsActivities;
1 like
workizzy's avatar
namespace App\Jobs;
use App\Models\ZoommerActivities;
use App\Models\ZoommerRequest;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;


class ValidatePickUp implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $zoommer_id;
    public $trace_id;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($zoommer_id, $trace_id)
    {
        //

        $this->zoommer_id = $zoommer_id;
        $this->trace_id = $trace_id; 
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $check = ZoommerActivities::where('trace_id', $this->trace_id)->first();
        if($check->complete == 0){
            $canceloffer = ZoomnerActivities::where('trace_id', $this->trace_id)->update(['incomplete' => 1]);
            if($canceloffer == 1){
                $returnOfferToTable = ZoommerRequest::where('trace_id', $this->trace_id)->update(['accept' => 0]);
            }
            
        }
    }
}

from the dispatching area

   if($process == 1){
            $createAtivities =  ZoommerActivities::create([
                'trace_id'      => $request->trace_id,
                'zoommer_id'    => $request->zoommer_id,
                'count_down'    => '45 : mins',
                'start_time'    => Carbon::now(),
                'end_time'      => Carbon::now()->addMinute(45),
                'name'          => $request->name,
                'package_description' => $request->package_description

            ]);

            ValidatePickUp::dispatch($request->zoommer_id, $request->trace_id)->delay(now()->addMinute(2));
            $response = [
                'orders' => "accepted"
            ];


       }else{
           $response = [
                'orders' => "Oops! try again"
            ];
            return response($response, 401);
       }
workizzy's avatar

@Sinnbeck At first, I didn't. but I have restarted it now and it is working perfectly right now. Thanks alot.

Sirik's avatar

try adding

<?php
    use App\ZoomsActivities;
1 like
workizzy's avatar

@Sirik

use App\Models\ZoomsActivities;

this works, and thanks more knowledge gained.

Please or to participate in this conversation.