Laravel queues not saving entity to DB












0















please help, I might be doing or understood something wrong.
I am creating a mass upload to database, which takes a little bit of time so I decided to make async all and proccess it in background using Laravel Queues.



In controller I create an associated list, which is passed to Laravel Job.



foreach($data as $row)
{
$instantArray = array();
$orderDate = PHPExcel_Shared_Date::ExcelToPHPObject($row[3]);
$issueDate = PHPExcel_Shared_Date::ExcelToPHPObject($row[4]);
$orderRow = array(
'invoice_no' => trim($row[0]),
'agent_id' => $row[1],
'issued_at' => $orderDate->format('Y-m-d'),
'received_at' => $issueDate->format('Y-m-d'),
);
$gameArray = array();
$invoiceOrdersArray = $orderRow;
}

$job = (new Import($invoiceOrdersArray));
dispatch($job);


In Laravel Job I am trying to create an entyty and upload it to database



class Import implements ShouldQueue
{
use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;
protected $importData;
public function __construct($importData)
{
$this->importData = $importData;
}

public function handle()
{
foreach($this->importData as $insert)
{
InvoicesOrder::create($insert);
}
}


However, every time I am trying I can see in my logs:



 #0 appUtilitiesUpdater.php(18): IlluminateFoundationBootstrapHandleExceptions->handleError(8, 'Trying to get p...', '...', 18, Array)
#1 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(348): ModulesAccountingEntitiesInvoicesOrder::AppUtilities{closure}(Object(ModulesAccountingEntitiesInvoicesOrder))
#2 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(199): IlluminateEventsDispatcher->IlluminateEvents{closure}('eloquent.creati...', Array)
#3 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(159): IlluminateEventsDispatcher->dispatch('eloquent.creati...', Array, true)
#4 vendorlaravelframeworksrcIlluminateDatabaseEloquentConcernsHasEvents.php(148): IlluminateEventsDispatcher->until('eloquent.creati...', Object(ModulesAccountingEntitiesInvoicesOrder))
#5 vendorlaravelframeworksrcIlluminateDatabaseEloquentModel.php(636): IlluminateDatabaseEloquentModel->fireModelEvent('creating')
#6 vendorlaravelframeworksrcIlluminateDatabaseEloquentModel.php(522): IlluminateDatabaseEloquentModel->performInsert(Object(IlluminateDatabaseEloquentBuilder))
#7 ModulesAccountingJobsImportFiles.php(39): IlluminateDatabaseEloquentModel->save()
#8 [internal function]: ModulesAccountingJobsImportFiles->handle()
#9 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(29): call_user_func_array(Array, Array)
#10 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(87): IlluminateContainerBoundMethod::IlluminateContainer{closure}()
#11 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(31): IlluminateContainerBoundMethod::callBoundMethod(Object(IlluminateFoundationApplication), Array, Object(Closure))
#12 vendorlaravelframeworksrcIlluminateContainerContainer.php(539): IlluminateContainerBoundMethod::call(Object(IlluminateFoundationApplication), Array, Array, NULL)
#13 vendorlaravelframeworksrcIlluminateBusDispatcher.php(94): IlluminateContainerContainer->call(Array)
#14 vendorlaravelframeworksrcIlluminatePipelinePipeline.php(114): IlluminateBusDispatcher->IlluminateBus{closure}(Object(ModulesAccountingJobsImportFiles))
#15 vendorlaravelframeworksrcIlluminatePipelinePipeline.php(102): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(ModulesAccountingJobsImportFiles))
#16 vendorlaravelframeworksrcIlluminateBusDispatcher.php(98): IlluminatePipelinePipeline->then(Object(Closure))
#17 vendorlaravelframeworksrcIlluminateQueueCallQueuedHandler.php(42): IlluminateBusDispatcher->dispatchNow(Object(ModulesAccountingJobsImportFiles), false)
#18 vendorlaravelframeworksrcIlluminateQueueJobsJob.php(69): IlluminateQueueCallQueuedHandler->call(Object(IlluminateQueueJobsRedisJob), Array)
#19 vendorlaravelframeworksrcIlluminateQueueWorker.php(317): IlluminateQueueJobsJob->fire()


Whenever I do it in controller it works fine, it just loads very long.
Maybe it is not possible to save entities in Job using queues?



Thank you.










share|improve this question





























    0















    please help, I might be doing or understood something wrong.
    I am creating a mass upload to database, which takes a little bit of time so I decided to make async all and proccess it in background using Laravel Queues.



    In controller I create an associated list, which is passed to Laravel Job.



    foreach($data as $row)
    {
    $instantArray = array();
    $orderDate = PHPExcel_Shared_Date::ExcelToPHPObject($row[3]);
    $issueDate = PHPExcel_Shared_Date::ExcelToPHPObject($row[4]);
    $orderRow = array(
    'invoice_no' => trim($row[0]),
    'agent_id' => $row[1],
    'issued_at' => $orderDate->format('Y-m-d'),
    'received_at' => $issueDate->format('Y-m-d'),
    );
    $gameArray = array();
    $invoiceOrdersArray = $orderRow;
    }

    $job = (new Import($invoiceOrdersArray));
    dispatch($job);


    In Laravel Job I am trying to create an entyty and upload it to database



    class Import implements ShouldQueue
    {
    use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;
    protected $importData;
    public function __construct($importData)
    {
    $this->importData = $importData;
    }

    public function handle()
    {
    foreach($this->importData as $insert)
    {
    InvoicesOrder::create($insert);
    }
    }


    However, every time I am trying I can see in my logs:



     #0 appUtilitiesUpdater.php(18): IlluminateFoundationBootstrapHandleExceptions->handleError(8, 'Trying to get p...', '...', 18, Array)
    #1 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(348): ModulesAccountingEntitiesInvoicesOrder::AppUtilities{closure}(Object(ModulesAccountingEntitiesInvoicesOrder))
    #2 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(199): IlluminateEventsDispatcher->IlluminateEvents{closure}('eloquent.creati...', Array)
    #3 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(159): IlluminateEventsDispatcher->dispatch('eloquent.creati...', Array, true)
    #4 vendorlaravelframeworksrcIlluminateDatabaseEloquentConcernsHasEvents.php(148): IlluminateEventsDispatcher->until('eloquent.creati...', Object(ModulesAccountingEntitiesInvoicesOrder))
    #5 vendorlaravelframeworksrcIlluminateDatabaseEloquentModel.php(636): IlluminateDatabaseEloquentModel->fireModelEvent('creating')
    #6 vendorlaravelframeworksrcIlluminateDatabaseEloquentModel.php(522): IlluminateDatabaseEloquentModel->performInsert(Object(IlluminateDatabaseEloquentBuilder))
    #7 ModulesAccountingJobsImportFiles.php(39): IlluminateDatabaseEloquentModel->save()
    #8 [internal function]: ModulesAccountingJobsImportFiles->handle()
    #9 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(29): call_user_func_array(Array, Array)
    #10 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(87): IlluminateContainerBoundMethod::IlluminateContainer{closure}()
    #11 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(31): IlluminateContainerBoundMethod::callBoundMethod(Object(IlluminateFoundationApplication), Array, Object(Closure))
    #12 vendorlaravelframeworksrcIlluminateContainerContainer.php(539): IlluminateContainerBoundMethod::call(Object(IlluminateFoundationApplication), Array, Array, NULL)
    #13 vendorlaravelframeworksrcIlluminateBusDispatcher.php(94): IlluminateContainerContainer->call(Array)
    #14 vendorlaravelframeworksrcIlluminatePipelinePipeline.php(114): IlluminateBusDispatcher->IlluminateBus{closure}(Object(ModulesAccountingJobsImportFiles))
    #15 vendorlaravelframeworksrcIlluminatePipelinePipeline.php(102): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(ModulesAccountingJobsImportFiles))
    #16 vendorlaravelframeworksrcIlluminateBusDispatcher.php(98): IlluminatePipelinePipeline->then(Object(Closure))
    #17 vendorlaravelframeworksrcIlluminateQueueCallQueuedHandler.php(42): IlluminateBusDispatcher->dispatchNow(Object(ModulesAccountingJobsImportFiles), false)
    #18 vendorlaravelframeworksrcIlluminateQueueJobsJob.php(69): IlluminateQueueCallQueuedHandler->call(Object(IlluminateQueueJobsRedisJob), Array)
    #19 vendorlaravelframeworksrcIlluminateQueueWorker.php(317): IlluminateQueueJobsJob->fire()


    Whenever I do it in controller it works fine, it just loads very long.
    Maybe it is not possible to save entities in Job using queues?



    Thank you.










    share|improve this question



























      0












      0








      0








      please help, I might be doing or understood something wrong.
      I am creating a mass upload to database, which takes a little bit of time so I decided to make async all and proccess it in background using Laravel Queues.



      In controller I create an associated list, which is passed to Laravel Job.



      foreach($data as $row)
      {
      $instantArray = array();
      $orderDate = PHPExcel_Shared_Date::ExcelToPHPObject($row[3]);
      $issueDate = PHPExcel_Shared_Date::ExcelToPHPObject($row[4]);
      $orderRow = array(
      'invoice_no' => trim($row[0]),
      'agent_id' => $row[1],
      'issued_at' => $orderDate->format('Y-m-d'),
      'received_at' => $issueDate->format('Y-m-d'),
      );
      $gameArray = array();
      $invoiceOrdersArray = $orderRow;
      }

      $job = (new Import($invoiceOrdersArray));
      dispatch($job);


      In Laravel Job I am trying to create an entyty and upload it to database



      class Import implements ShouldQueue
      {
      use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;
      protected $importData;
      public function __construct($importData)
      {
      $this->importData = $importData;
      }

      public function handle()
      {
      foreach($this->importData as $insert)
      {
      InvoicesOrder::create($insert);
      }
      }


      However, every time I am trying I can see in my logs:



       #0 appUtilitiesUpdater.php(18): IlluminateFoundationBootstrapHandleExceptions->handleError(8, 'Trying to get p...', '...', 18, Array)
      #1 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(348): ModulesAccountingEntitiesInvoicesOrder::AppUtilities{closure}(Object(ModulesAccountingEntitiesInvoicesOrder))
      #2 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(199): IlluminateEventsDispatcher->IlluminateEvents{closure}('eloquent.creati...', Array)
      #3 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(159): IlluminateEventsDispatcher->dispatch('eloquent.creati...', Array, true)
      #4 vendorlaravelframeworksrcIlluminateDatabaseEloquentConcernsHasEvents.php(148): IlluminateEventsDispatcher->until('eloquent.creati...', Object(ModulesAccountingEntitiesInvoicesOrder))
      #5 vendorlaravelframeworksrcIlluminateDatabaseEloquentModel.php(636): IlluminateDatabaseEloquentModel->fireModelEvent('creating')
      #6 vendorlaravelframeworksrcIlluminateDatabaseEloquentModel.php(522): IlluminateDatabaseEloquentModel->performInsert(Object(IlluminateDatabaseEloquentBuilder))
      #7 ModulesAccountingJobsImportFiles.php(39): IlluminateDatabaseEloquentModel->save()
      #8 [internal function]: ModulesAccountingJobsImportFiles->handle()
      #9 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(29): call_user_func_array(Array, Array)
      #10 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(87): IlluminateContainerBoundMethod::IlluminateContainer{closure}()
      #11 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(31): IlluminateContainerBoundMethod::callBoundMethod(Object(IlluminateFoundationApplication), Array, Object(Closure))
      #12 vendorlaravelframeworksrcIlluminateContainerContainer.php(539): IlluminateContainerBoundMethod::call(Object(IlluminateFoundationApplication), Array, Array, NULL)
      #13 vendorlaravelframeworksrcIlluminateBusDispatcher.php(94): IlluminateContainerContainer->call(Array)
      #14 vendorlaravelframeworksrcIlluminatePipelinePipeline.php(114): IlluminateBusDispatcher->IlluminateBus{closure}(Object(ModulesAccountingJobsImportFiles))
      #15 vendorlaravelframeworksrcIlluminatePipelinePipeline.php(102): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(ModulesAccountingJobsImportFiles))
      #16 vendorlaravelframeworksrcIlluminateBusDispatcher.php(98): IlluminatePipelinePipeline->then(Object(Closure))
      #17 vendorlaravelframeworksrcIlluminateQueueCallQueuedHandler.php(42): IlluminateBusDispatcher->dispatchNow(Object(ModulesAccountingJobsImportFiles), false)
      #18 vendorlaravelframeworksrcIlluminateQueueJobsJob.php(69): IlluminateQueueCallQueuedHandler->call(Object(IlluminateQueueJobsRedisJob), Array)
      #19 vendorlaravelframeworksrcIlluminateQueueWorker.php(317): IlluminateQueueJobsJob->fire()


      Whenever I do it in controller it works fine, it just loads very long.
      Maybe it is not possible to save entities in Job using queues?



      Thank you.










      share|improve this question
















      please help, I might be doing or understood something wrong.
      I am creating a mass upload to database, which takes a little bit of time so I decided to make async all and proccess it in background using Laravel Queues.



      In controller I create an associated list, which is passed to Laravel Job.



      foreach($data as $row)
      {
      $instantArray = array();
      $orderDate = PHPExcel_Shared_Date::ExcelToPHPObject($row[3]);
      $issueDate = PHPExcel_Shared_Date::ExcelToPHPObject($row[4]);
      $orderRow = array(
      'invoice_no' => trim($row[0]),
      'agent_id' => $row[1],
      'issued_at' => $orderDate->format('Y-m-d'),
      'received_at' => $issueDate->format('Y-m-d'),
      );
      $gameArray = array();
      $invoiceOrdersArray = $orderRow;
      }

      $job = (new Import($invoiceOrdersArray));
      dispatch($job);


      In Laravel Job I am trying to create an entyty and upload it to database



      class Import implements ShouldQueue
      {
      use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;
      protected $importData;
      public function __construct($importData)
      {
      $this->importData = $importData;
      }

      public function handle()
      {
      foreach($this->importData as $insert)
      {
      InvoicesOrder::create($insert);
      }
      }


      However, every time I am trying I can see in my logs:



       #0 appUtilitiesUpdater.php(18): IlluminateFoundationBootstrapHandleExceptions->handleError(8, 'Trying to get p...', '...', 18, Array)
      #1 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(348): ModulesAccountingEntitiesInvoicesOrder::AppUtilities{closure}(Object(ModulesAccountingEntitiesInvoicesOrder))
      #2 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(199): IlluminateEventsDispatcher->IlluminateEvents{closure}('eloquent.creati...', Array)
      #3 vendorlaravelframeworksrcIlluminateEventsDispatcher.php(159): IlluminateEventsDispatcher->dispatch('eloquent.creati...', Array, true)
      #4 vendorlaravelframeworksrcIlluminateDatabaseEloquentConcernsHasEvents.php(148): IlluminateEventsDispatcher->until('eloquent.creati...', Object(ModulesAccountingEntitiesInvoicesOrder))
      #5 vendorlaravelframeworksrcIlluminateDatabaseEloquentModel.php(636): IlluminateDatabaseEloquentModel->fireModelEvent('creating')
      #6 vendorlaravelframeworksrcIlluminateDatabaseEloquentModel.php(522): IlluminateDatabaseEloquentModel->performInsert(Object(IlluminateDatabaseEloquentBuilder))
      #7 ModulesAccountingJobsImportFiles.php(39): IlluminateDatabaseEloquentModel->save()
      #8 [internal function]: ModulesAccountingJobsImportFiles->handle()
      #9 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(29): call_user_func_array(Array, Array)
      #10 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(87): IlluminateContainerBoundMethod::IlluminateContainer{closure}()
      #11 vendorlaravelframeworksrcIlluminateContainerBoundMethod.php(31): IlluminateContainerBoundMethod::callBoundMethod(Object(IlluminateFoundationApplication), Array, Object(Closure))
      #12 vendorlaravelframeworksrcIlluminateContainerContainer.php(539): IlluminateContainerBoundMethod::call(Object(IlluminateFoundationApplication), Array, Array, NULL)
      #13 vendorlaravelframeworksrcIlluminateBusDispatcher.php(94): IlluminateContainerContainer->call(Array)
      #14 vendorlaravelframeworksrcIlluminatePipelinePipeline.php(114): IlluminateBusDispatcher->IlluminateBus{closure}(Object(ModulesAccountingJobsImportFiles))
      #15 vendorlaravelframeworksrcIlluminatePipelinePipeline.php(102): IlluminatePipelinePipeline->IlluminatePipeline{closure}(Object(ModulesAccountingJobsImportFiles))
      #16 vendorlaravelframeworksrcIlluminateBusDispatcher.php(98): IlluminatePipelinePipeline->then(Object(Closure))
      #17 vendorlaravelframeworksrcIlluminateQueueCallQueuedHandler.php(42): IlluminateBusDispatcher->dispatchNow(Object(ModulesAccountingJobsImportFiles), false)
      #18 vendorlaravelframeworksrcIlluminateQueueJobsJob.php(69): IlluminateQueueCallQueuedHandler->call(Object(IlluminateQueueJobsRedisJob), Array)
      #19 vendorlaravelframeworksrcIlluminateQueueWorker.php(317): IlluminateQueueJobsJob->fire()


      Whenever I do it in controller it works fine, it just loads very long.
      Maybe it is not possible to save entities in Job using queues?



      Thank you.







      php asynchronous laravel-5 eloquent






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 13:52







      Arūnas Kiršis

















      asked Nov 15 '18 at 13:13









      Arūnas KiršisArūnas Kiršis

      488




      488
























          3 Answers
          3






          active

          oldest

          votes


















          1














          In your job you insert the data in the $this->importData property.



          but in the handle method, you're looping over $invoiceOrdersArray, where does that come from?



          Should your loop, not look like this?



          foreach($this->importData as $insert)
          {
          InvoicesOrder::create($insert);
          }


          You don't even need the unused $order variable in the handle method.



          Also, I think you need to use the InvoicesOrder class in the job. So the whole thing might look like this.



          use namespace/to/InvoicesOrder;

          class Import implements ShouldQueue
          {
          use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;

          protected $importData;
          public function __construct($importData)
          {
          $this->importData = $importData;
          }

          public function handle()
          {
          foreach($$this->importData as $insert)
          {
          InvoicesOrder::create($insert);
          }
          }
          }





          share|improve this answer


























          • Yes, corrected my question, there is a little bit more going on in the Job, but I just deleted everything what is not necessary for the question.

            – Arūnas Kiršis
            Nov 15 '18 at 13:53











          • The stack trace says it is trying to locate your InvoiceOrder in the ModulesAccountingEntitiesInvoicesOrder namespace, which is the same as the job. Is that definitely correct?

            – John Halsey
            Nov 15 '18 at 15:34





















          0














          If anyone bumps into the similar problem, check in your entity if you are using any kind of presenters (I was using presentable trait), which adds fields like created/updated by. And what do we get from Auth::user()->id... Trying to get a property of non object, as queue is not an user.






          share|improve this answer































            0














            Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:restart command:



            php artisan queue:restart





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320316%2flaravel-queues-not-saving-entity-to-db%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              In your job you insert the data in the $this->importData property.



              but in the handle method, you're looping over $invoiceOrdersArray, where does that come from?



              Should your loop, not look like this?



              foreach($this->importData as $insert)
              {
              InvoicesOrder::create($insert);
              }


              You don't even need the unused $order variable in the handle method.



              Also, I think you need to use the InvoicesOrder class in the job. So the whole thing might look like this.



              use namespace/to/InvoicesOrder;

              class Import implements ShouldQueue
              {
              use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;

              protected $importData;
              public function __construct($importData)
              {
              $this->importData = $importData;
              }

              public function handle()
              {
              foreach($$this->importData as $insert)
              {
              InvoicesOrder::create($insert);
              }
              }
              }





              share|improve this answer


























              • Yes, corrected my question, there is a little bit more going on in the Job, but I just deleted everything what is not necessary for the question.

                – Arūnas Kiršis
                Nov 15 '18 at 13:53











              • The stack trace says it is trying to locate your InvoiceOrder in the ModulesAccountingEntitiesInvoicesOrder namespace, which is the same as the job. Is that definitely correct?

                – John Halsey
                Nov 15 '18 at 15:34


















              1














              In your job you insert the data in the $this->importData property.



              but in the handle method, you're looping over $invoiceOrdersArray, where does that come from?



              Should your loop, not look like this?



              foreach($this->importData as $insert)
              {
              InvoicesOrder::create($insert);
              }


              You don't even need the unused $order variable in the handle method.



              Also, I think you need to use the InvoicesOrder class in the job. So the whole thing might look like this.



              use namespace/to/InvoicesOrder;

              class Import implements ShouldQueue
              {
              use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;

              protected $importData;
              public function __construct($importData)
              {
              $this->importData = $importData;
              }

              public function handle()
              {
              foreach($$this->importData as $insert)
              {
              InvoicesOrder::create($insert);
              }
              }
              }





              share|improve this answer


























              • Yes, corrected my question, there is a little bit more going on in the Job, but I just deleted everything what is not necessary for the question.

                – Arūnas Kiršis
                Nov 15 '18 at 13:53











              • The stack trace says it is trying to locate your InvoiceOrder in the ModulesAccountingEntitiesInvoicesOrder namespace, which is the same as the job. Is that definitely correct?

                – John Halsey
                Nov 15 '18 at 15:34
















              1












              1








              1







              In your job you insert the data in the $this->importData property.



              but in the handle method, you're looping over $invoiceOrdersArray, where does that come from?



              Should your loop, not look like this?



              foreach($this->importData as $insert)
              {
              InvoicesOrder::create($insert);
              }


              You don't even need the unused $order variable in the handle method.



              Also, I think you need to use the InvoicesOrder class in the job. So the whole thing might look like this.



              use namespace/to/InvoicesOrder;

              class Import implements ShouldQueue
              {
              use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;

              protected $importData;
              public function __construct($importData)
              {
              $this->importData = $importData;
              }

              public function handle()
              {
              foreach($$this->importData as $insert)
              {
              InvoicesOrder::create($insert);
              }
              }
              }





              share|improve this answer















              In your job you insert the data in the $this->importData property.



              but in the handle method, you're looping over $invoiceOrdersArray, where does that come from?



              Should your loop, not look like this?



              foreach($this->importData as $insert)
              {
              InvoicesOrder::create($insert);
              }


              You don't even need the unused $order variable in the handle method.



              Also, I think you need to use the InvoicesOrder class in the job. So the whole thing might look like this.



              use namespace/to/InvoicesOrder;

              class Import implements ShouldQueue
              {
              use InteractsWithQueue, SerializesModels, Queueable, Dispatchable;

              protected $importData;
              public function __construct($importData)
              {
              $this->importData = $importData;
              }

              public function handle()
              {
              foreach($$this->importData as $insert)
              {
              InvoicesOrder::create($insert);
              }
              }
              }






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 15 '18 at 13:32

























              answered Nov 15 '18 at 13:25









              John HalseyJohn Halsey

              898825




              898825













              • Yes, corrected my question, there is a little bit more going on in the Job, but I just deleted everything what is not necessary for the question.

                – Arūnas Kiršis
                Nov 15 '18 at 13:53











              • The stack trace says it is trying to locate your InvoiceOrder in the ModulesAccountingEntitiesInvoicesOrder namespace, which is the same as the job. Is that definitely correct?

                – John Halsey
                Nov 15 '18 at 15:34





















              • Yes, corrected my question, there is a little bit more going on in the Job, but I just deleted everything what is not necessary for the question.

                – Arūnas Kiršis
                Nov 15 '18 at 13:53











              • The stack trace says it is trying to locate your InvoiceOrder in the ModulesAccountingEntitiesInvoicesOrder namespace, which is the same as the job. Is that definitely correct?

                – John Halsey
                Nov 15 '18 at 15:34



















              Yes, corrected my question, there is a little bit more going on in the Job, but I just deleted everything what is not necessary for the question.

              – Arūnas Kiršis
              Nov 15 '18 at 13:53





              Yes, corrected my question, there is a little bit more going on in the Job, but I just deleted everything what is not necessary for the question.

              – Arūnas Kiršis
              Nov 15 '18 at 13:53













              The stack trace says it is trying to locate your InvoiceOrder in the ModulesAccountingEntitiesInvoicesOrder namespace, which is the same as the job. Is that definitely correct?

              – John Halsey
              Nov 15 '18 at 15:34







              The stack trace says it is trying to locate your InvoiceOrder in the ModulesAccountingEntitiesInvoicesOrder namespace, which is the same as the job. Is that definitely correct?

              – John Halsey
              Nov 15 '18 at 15:34















              0














              If anyone bumps into the similar problem, check in your entity if you are using any kind of presenters (I was using presentable trait), which adds fields like created/updated by. And what do we get from Auth::user()->id... Trying to get a property of non object, as queue is not an user.






              share|improve this answer




























                0














                If anyone bumps into the similar problem, check in your entity if you are using any kind of presenters (I was using presentable trait), which adds fields like created/updated by. And what do we get from Auth::user()->id... Trying to get a property of non object, as queue is not an user.






                share|improve this answer


























                  0












                  0








                  0







                  If anyone bumps into the similar problem, check in your entity if you are using any kind of presenters (I was using presentable trait), which adds fields like created/updated by. And what do we get from Auth::user()->id... Trying to get a property of non object, as queue is not an user.






                  share|improve this answer













                  If anyone bumps into the similar problem, check in your entity if you are using any kind of presenters (I was using presentable trait), which adds fields like created/updated by. And what do we get from Auth::user()->id... Trying to get a property of non object, as queue is not an user.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 16 '18 at 6:41









                  Arūnas KiršisArūnas Kiršis

                  488




                  488























                      0














                      Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:restart command:



                      php artisan queue:restart





                      share|improve this answer




























                        0














                        Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:restart command:



                        php artisan queue:restart





                        share|improve this answer


























                          0












                          0








                          0







                          Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:restart command:



                          php artisan queue:restart





                          share|improve this answer













                          Since queue workers are long-lived processes, they will not pick up changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:restart command:



                          php artisan queue:restart






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 16 '18 at 6:55









                          Gajanan TagadpalleGajanan Tagadpalle

                          613




                          613






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320316%2flaravel-queues-not-saving-entity-to-db%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Florida Star v. B. J. F.

                              Error while running script in elastic search , gateway timeout

                              Adding quotations to stringified JSON object values