![]() Ignore the job when the models are missing ![]() In that case, you have two options to handle this. And by the time your queue worker picks up the job, the model is all gone and the job fails with a ModelNotFoundException. A database transaction rollback, an exception, or something else that would cause your model to get deleted. A lot can happen in that time, even if it's just one second. Unless your queue driver is set to sync, your queued jobs will be executed at some point in the future. Model was deleted between job dispatch and job execution at this point, the model is not saved yet. ![]() The same applies when creating instances through Model::make(): Make sure to call the ->save() method to save it to the database At this point, the model is not saved yet. Once you're finished assigning properties, make sure to call the ->save() method to save it to the database. $model = new Model creates a new model instance, but it still hasn't saved it to the database. Make sure you understand the difference between Model::create(), Model::make(), and new Model in your application. Luckily all three reasons are easy to fix. The job/listener was dispatched within a database transaction that was later rolled back.The model was deleted between job dispatch and job execution.You did not save the model to the database before dispatching the job.There's a couple main reasons why this can happen: This is a very common error, especially on larger scale projects when lots of jobs are being processed and unexpected things happens. 3 min read Photo by Erik Mclean / Unsplash Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |