skip to Main Content

I want to run Laravel Job. I’m using supervisord on Centos 7 (with php 7.3). And I want to make query in laravel Job Class. But when I try to make it, It’s giving error in below. I wonder where I’m doing it wrong? My Error:

BadMethodCallException: Call to undefined method IlluminateDatabaseEloquentBuilder::all() in /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50
Stack trace:
#0 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php(36): IlluminateDatabaseEloquentBuilder::throwBadMethodCallException('all')
#1 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1356): IlluminateDatabaseEloquentBuilder->forwardCallTo(Object(IlluminateDatabaseQueryBuilder), 'all', Array)
#2 /home/merryedu/web/app/Jobs/VideoLinkCheckerJob.php(35): IlluminateDatabaseEloquentBuilder->__call('all', Array)
#3 [internal function]: AppJobsVideoLinkCheckerJob->handle()
#4 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#5 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): IlluminateContainerBoundMethod::IlluminateContainer{closure}()
#6 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): IlluminateContainerBoundMethod::callBoundMethod(Object(IlluminateFoundationApplication), Array, Object(Closure))
#7 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): IlluminateContainerBoundMethod::call(Object(IlluminateFoundationApplication), Array, Array, NULL)
#8 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(94): IlluminateContainerContainer->call(Array)
#9 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): IlluminateBusDispatcher->IlluminateBus{closure}(Object(AppJobsVideoLinkCheckerJob))
#10 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(104): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(AppJobsVideoLinkCheckerJob))
#11 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(98): IlluminatePipelinePipeline->then(Object(Closure))
#12 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(49): IlluminateBusDispatcher->dispatchNow(Object(AppJobsVideoLinkCheckerJob), false)
#13 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(88): IlluminateQueueCallQueuedHandler->call(Object(IlluminateQueueJobsDatabaseJob), Array)
#14 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(327): IlluminateQueueJobsJob->fire()
#15 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(277): IlluminateQueueWorker->process('database', Object(IlluminateQueueJobsDatabaseJob), Object(IlluminateQueueWorkerOptions))
#16 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): IlluminateQueueWorker->runJob(Object(IlluminateQueueJobsDatabaseJob), 'database', Object(IlluminateQueueWorkerOptions))
#17 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): IlluminateQueueWorker->daemon('database', 'default', Object(IlluminateQueueWorkerOptions))
#18 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): IlluminateQueueConsoleWorkCommand->runWorker('database', 'default')
#19 [internal function]: IlluminateQueueConsoleWorkCommand->handle()
#20 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#21 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): IlluminateContainerBoundMethod::IlluminateContainer{closure}()
#22 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): IlluminateContainerBoundMethod::callBoundMethod(Object(IlluminateFoundationApplication), Array, Object(Closure))
#23 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): IlluminateContainerBoundMethod::call(Object(IlluminateFoundationApplication), Array, Array, NULL)
#24 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): IlluminateContainerContainer->call(Array)
#25 /home/merryedu/web/vendor/symfony/console/Command/Command.php(255): IlluminateConsoleCommand->execute(Object(SymfonyComponentConsoleInputArgvInput), Object(IlluminateConsoleOutputStyle))
#26 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): SymfonyComponentConsoleCommandCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(IlluminateConsoleOutputStyle))
#27 /home/merryedu/web/vendor/symfony/console/Application.php(921): IlluminateConsoleCommand->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#28 /home/merryedu/web/vendor/symfony/console/Application.php(273): SymfonyComponentConsoleApplication->doRunCommand(Object(IlluminateQueueConsoleWorkCommand), Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#29 /home/merryedu/web/vendor/symfony/console/Application.php(149): SymfonyComponentConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#30 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#31 /home/merryedu/web/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): IlluminateConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#32 /home/merryedu/web/artisan(37): IlluminateFoundationConsoleKernel->handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#33 {main}

My system under;
Laravel 5.8,
PHP 7.3,
Queue on Database,
Supervisor installed,
Centos 7 latest version

"VideoLinkCheckerJob.php"
<?php

namespace AppJobs;

use AppHttpControllersSystemConfigValue;
use AppHttpControllersSystemVideoLinkCheckerController;
use AppArticles;
use IlluminateBusQueueable;
use IlluminateQueueSerializesModels;
use IlluminateQueueInteractsWithQueue;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use IlluminateSupportFacadesLog;

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

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Log::info("Video eğitim link kontrolcüsü başlatıldı!");
        $articles = Articles::all();
        foreach ($articles as $article) {
            if($article->bot->lesson=='math') {
                $status = VideoLinkCheckerController::videoLinkStatus(ConfigValue::get('a_video_host').$article->bot_video_id.".mp4");
                Log::info($article->bot->code.' içindeki '.$article->google_video_id.' kodlu eğitimin durumu '.$status);
                $article->video_link_status = $status;
                $article->save();
            } elseif ($article->lesson->code=='physics') {
                $status = VideoLinkCheckerController::videoLinkStatus(ConfigValue::get('b_video_host').$article->bot_video_id.".mp4");
                Log::info($article->bot->code.' içindeki '.$article->google_video_id.' kodlu eğitimin durumu '.$status);
                $article->video_link_status = $status;
                $article->save();
            }
        }
        Log::info("Video eğitim link kontrolcüsü tamamlandı!");
    }
}

And
“AdminArticleController.php”

namespace AppHttpControllers;

use AppBot;
use AppCategory;
use AppHttpControllersSystemConfigValue;
use AppHttpControllersSystemVideoLinkCheckerController;
use AppJobsVideoLinkCheckerJob;
use AppArticles;
use AppTag;
use IlluminateHttpRequest;
use IlluminateSupportFacadesArtisan;

class AdminArticleController extends Controller
{
    public function __construct()
    {
        $this->middleware('admin');
    }

    public function videoLinkChecker()
    {
        VideoLinkCheckerJob::dispatch();
        return back()->with('success', 'İşlem başlatıldı tamamlandığında raporu Eğitimler sayfasında görüntüleyebilirsiniz!');
    }
}

BadMethodCallException: Call to undefined method
IlluminateDatabaseEloquentBuilder::all() in
/home/merryedu/web/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:50

2

Answers


  1. Chosen as BEST ANSWER
    <?php
    
    namespace App;
    
    use IlluminateDatabaseEloquentModel;
    
    class Article extends Model
    {
        protected $table = 'articles';
    
        protected $fillable = [
            'bot_id', 'bot_video_id', 'category_id', 'url', 'title', 'description', 'duration', 'lesson', 'views', 'like', 'dislike', 'status', 'video_link_status',
        ];
    
        public function category()
        {
            return $this->belongsTo('AppCategory');
        }
    
        public function tag()
        {
            return $this->hasMany('AppArticleTag');
        }
    
        public function bot()
        {
            return $this->belongsTo('AppBot');
        }
    }
    

  2. You are dispatching a job in a wrong way. Try like this

       public function videoLinkChecker()
        {
            dispatch(new VideoLinkCheckerJob());
            return back()->with('success', 'İşlem başlatıldı tamamlandığında raporu Eğitimler sayfasında görüntüleyebilirsiniz!');
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search