Я пытаюсь использовать очереди в Laravel и для этой цели установил Redis и Horizon.
Мои пользователи могут загружать изображения через веб-интерфейс.Когда это происходит, он вызывает метод store
:
public function store(Stream $stream)
{
//Validate the request.
$validate = request()->validate([
'file' => 'mimes:jpeg,jpg,bmp,png,gif,pdf',
]);
ImportDocuments::dispatch($stream);
}
В моем классе Jobs/ImportDocuments.php
у меня есть этот код:
class ImportDocuments implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $stream;
/**
* Create a new job instance.
*
* @param Document $document
* @return void
*/
public function __construct(Stream $stream)
{
$this->stream = $stream;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//Store the actual document. returns the path.
$store = request()->file('file')->store($this->stream->token);
//Set the attributes to save to DB.
$attributes['name'] = request()->file->getClientOriginalName();
$attributes['path'] = $store;
//Add the document to the database.
$this->stream->addDocuments($attributes);
}
}
Для справки: addDocuments()
Метод выглядит следующим образом:
Stream.php
:
public function addDocuments(array $attributes)
{
return $this->documents()->create($attributes);
}
Всякий раз, когда я пытаюсь загрузить изображение, я получаю сообщение об ошибке ниже:
Class dispatch does not exist {"userId":1,"email":"myemail@myapp.com","exception":"[object] (ReflectionException(code: -1): Class dispatch does not exist at /Users/MyUsername/Sites/playground/vendor/laravel/framework/src/Illuminate/Container/Container.php:779)
- Redisработает
- предисловие / предустановка установлено
- Horizon работает
- Состояние горизонта говорит "Активен"
Что я здесь не так делаю?