Why are you trying to create a single user on a queue? It is a simple task that you can easily do directly in the controller. Queues are for time consuming tasks. Dispatching the job, probably takes the same time as saving the user
Dec 23, 2021
3
Level 1
No query results for model INSIDE JOB
Hi, i want make a simple task for queue laravel. I have this error in "failed_jobs" Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model....... What did i do wrong?
//controller
public function addUser(Request $req)
{
$user = new User;
$user->name = $req->name;
$user->username = $req->username;
$user->email = $req->email;
$user->password = bcrypt($req->password);
dispatch(new adduser($user));
// adduser::dispatch();
return 'added';
}
//Job
class adduser implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $user;
public function __construct($user)
{
$this->user = new User;
$this->user = $user;
}
public function handle()
{
$this->user->save();
}
}
Level 102
@ioiofadhil yeah. You could make it work by saving first, giving the user an ID. Then the job can find the user by that ID :)
Please or to participate in this conversation.