我想使用Laravel
队列作业的帽子,
这是我的工作代码
class PostComment implements ShouldQueue
{ 使用Dispatchable,InteractsWithQueue,Queueable,SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($comments)
{
$this->comments = $comments;
}
/**
* Execute the job.
*
* @return void
*/
public function handle(Request $request)
{
// $this->comments->create($request->all());
$findNews = News::find($id);
if($findNews){
$comments = Comment::create($this->comments);
return $comments;
}
//
}
这是我的控制器
public function postComment($request,$id)
{
$findNews = $this->news->find($id);
if($findNews){
$comments = $this->comments->create([
'content' => $request->content,
'user_id' => auth()->user()->id,
'news_id' => $findNews->id,
]);
PostComment::dispatch($comments);
return response()->json([
'Message' => 'Comment succesfull',
'data' => $comments,
]);
}
}
但是当我运行 php artisan:queue工作
工作失败了
我的代码有什么问题?