Answer the question
In order to leave comments, you need to log in
Why RelationNotFoundException when executing a Job in a queue?
Hello. There is a many-to-many relationship with a table respondent_answer
(laravel 5.3)
class Respondent {
// ...
public function answers()
{
return $this->belongsToMany(Answer::class);
}
}
class Answer {
// ...
public function respondents()
{
return $this->belongsToMany(Respondent::class);
}
}
Job
that is executed in the queueclass AnalyzeRespondentAnswersJob implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
// ...
public function handle()
{
$respondent = $this->event->respondent->fresh(['answers']); // тут падает ошибка RelationNotFoundException
// ...
}
}
production.ERROR: exception 'Illuminate\Database\Eloquent\RelationNotFoundException' with message 'Call to undefined relationship [answers] on model [App\Models\Respondent].'
answers
exists, and in tinker it works correctly. Also on another server exactly the same code works without errors. composer dump
php artisan cache:clear
php artisan clear-compiled
php artisan optimize
php artisan queue:restart
service nginx restart
service php-fpm restart
Answer the question
In order to leave comments, you need to log in
the problem was in php-fpm caching https://friendhosting.net/blog/kyeshirovanie-php-f...
Set up xdebug for yourself, put a breakpoint in the job and see what comes there. With some combination of keys (as on Windows xs) you can open the "console" - pull yourself the necessary relations / methods and look.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question