Laravel队列错误

时间:2016-08-08 09:16:29

标签: laravel exception

我正在使用Laravel队列,我写了一个将更新我的数据库变量的Job。但我无法测试我的功能,因为当我执行php artisan queue:listen时会抛出Class not Found异常。我无法调试错误。

3 个答案:

答案 0 :(得分:0)

我怀疑你忘记了import你的班级或者没有正确导入到顶层,这就是为什么laravel无法找到你想要的班级{{1 }}

答案 1 :(得分:0)

这就是我从模型中调用这份工作的方式。

public function getVisitedCountriesCountAttribute()
{
    $this->dispatch(new CalculateTotalCountriesVisited($this));  
    return $this->total_countries;
}

这是作业类

 <?php

namespace App\Jobs;

use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Bus\SelfHandling;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Trip;
use App\Location;

class CalculateTotalCountriesVisited extends Job implements SelfHandling, ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    protected $trip;

    /**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct(Trip $trip)
{
    $this->trip = $trip;
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    dd("in calcultae total countries");
    $visitedCountries = new Collection();

    $places_been = $this->locations()->where('been',1)->get();
    foreach ($places_been as $plans) {
        $location = Location::find($plans->id);
        if($location){
            if($location->country){
                $visitedCountries->push($location->country);
            }
        }
    }

    $photos_tagged = $this->media()->get();
    foreach ($photos_tagged as $media) {
        $location = Location::find($media->location_id);
        if($location){
            if($location->country){
                $visitedCountries->push($location->country);
            }
        }
    }

    $posts_tagged = $this->posts()->get();
    foreach ($posts_tagged as $posts) {
        $location = Location::find($posts->location_id);
        if($location){
            if($location->country){
                $visitedCountries->push($location->country);
            }
        }
    }

    $visitedCountries = $visitedCountries->unique('short_name');
    $this->total_countries = $visitedCountries->count();
    $this->save();
}
}

答案 2 :(得分:-1)

这是我查看Laravel Log

时得到的结果
     2016-08-08 08:43:47] local.ERROR: ErrorException: Class 'App\Http\Controllers\TripsController' not found in /Users/mereeva/sites/rdb-ws/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php:129
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Class 'Appname...', '/Users/mereeva/...', 129)
#1 /Users/mereeva/sites/rdb-ws/vendor/pragmarx/tracker/src/Support/Exceptions/Handler.php(63): call_user_func(Array, 2, 'Class 'Appname...', '/Users/mereeva/...', 129)
#2 [internal function]: PragmaRX\Tracker\Support\Exceptions\Handler->handleError(2, 'Class 'Appname...', '/Users/mereeva/...', 129, Array)
#3 /Users/mereeva/sites/rdb-ws/vendor/jeremeamia/SuperClosure/src/SerializableClosure.php(129): Closure->bindTo(NULL, 'App\\Htt...')
#4 [internal function]: SuperClosure\SerializableClosure->unserialize('a:5:{s:4:"code"...')
#5 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(300): unserialize('C:32:"SuperClos...')
#6 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Mail/Mailer.php(286): Illuminate\Mail\Mailer->getQueuedCallable(Array)
#7 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(129): Illuminate\Mail\Mailer->handleQueuedMessage(Object(Illuminate\Queue\Jobs\RedisJob), Array)
#8 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Queue/Jobs/RedisJob.php(50): Illuminate\Queue\Jobs\Job->resolveAndFire(Array)
#9 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(208): Illuminate\Queue\Jobs\RedisJob->fire()
#10 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(158): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), '0', '0')
#11 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(108): Illuminate\Queue\Worker->pop('', 'default', '0', '3', '0')
#12 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(70): Illuminate\Queue\Console\WorkCommand->runWorker('', 'default', '0', '128', false)
#13 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#14 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Container/Container.php(503): call_user_func_array(Array, Array)
#15 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Console/Command.php(150): Illuminate\Container\Container->call(Array)
#16 /Users/mereeva/sites/rdb-ws/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /Users/mereeva/sites/rdb-ws/vendor/symfony/console/Application.php(838): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /Users/mereeva/sites/rdb-ws/vendor/symfony/console/Application.php(189): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /Users/mereeva/sites/rdb-ws/vendor/symfony/console/Application.php(120): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 /Users/mereeva/sites/rdb-ws/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /Users/mereeva/sites/rdb-ws/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 {main}  

在控制台中,我得到了     [ErrorException]   Class&#39; Resdagboken \ Http \ Controllers \ TripsController&#39;找不到