Controller:
$model = User::find(1);
dispatch(new ModelSave($model));
Job
public function handle()
{
//
$this->model->save();
}
Job exception
Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\Device]. in E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php:452
Stack trace:
#0 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(85): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\SerializesAndRestoresModelIdentifiers.php(55): App\Jobs\ModelSave->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\SerializesModels.php(45): App\Jobs\ModelSave->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: App\Jobs\ModelSave->__wakeup()
#4 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\CallQueuedHandler.php(42): unserialize('O:18:"App\\Jobs\\...')
#5 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\Jobs\Job.php(83): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\DatabaseJob), Array)
#6 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(327): Illuminate\Queue\Jobs\Job->fire()
#7 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(277): Illuminate\Queue\Worker->process('database', Object(Illuminate\Queue\Jobs\DatabaseJob), Object(Illuminate\Queue\WorkerOptions))
#8 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\DatabaseJob), 'database', Object(Illuminate\Queue\WorkerOptions))
#9 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(102): Illuminate\Queue\Worker->daemon('database', 'modelsave', Object(Illuminate\Queue\WorkerOptions))
#10 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Queue\Console\WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('database', 'modelsave')
#11 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#12 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#13 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Container\Container.php(572): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Console\Command.php(183): Illuminate\Container\Container->call(Array)
#17 E:\server\wwwroot\xiaohoumengqi\vendor\symfony\console\Command\Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Console\Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#19 E:\server\wwwroot\xiaohoumengqi\vendor\symfony\console\Application.php(1009): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 E:\server\wwwroot\xiaohoumengqi\vendor\symfony\console\Application.php(273): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#21 E:\server\wwwroot\xiaohoumengqi\vendor\symfony\console\Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Console\Application.php(89): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 E:\server\wwwroot\xiaohoumengqi\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 E:\server\wwwroot\xiaohoumengqi\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main}
對模型原理不懂,難道要在佇列 重新new
或者 重新查詢
,重新賦值,再重新save
嗎?
本作品採用《CC 協議》,轉載必須註明作者和本文連結