Error log saying no query results found but there are records

Posted 1 month ago by ChrisF79

I just don't understand this error. I'm working on an app where I download records from a server and store them in a temporary table called rets_property_res_naples and then in a console command, they get selected, transformed a bit, then put into a "master" table.

I'm now getting the below error and I just don't understand it. If I go into php artisan tinker and do a \App\Models\TempListingNaples::all(), I get all of the records!

Like I said, I just don't understand so why would it pull fine from the model but the console command couldn't?

Error Message

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\TempListingNaples]. in /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:454
Stack trace:
#0 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(85): Illuminate\Database\Eloquent\Builder->firstOrFail()
#1 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesAndRestoresModelIdentifiers.php(55): App\Jobs\ProcessListing->restoreModel(Object(Illuminate\Contracts\Database\ModelIdentifier))
#2 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/SerializesModels.php(45): App\Jobs\ProcessListing->getRestoredPropertyValue(Object(Illuminate\Contracts\Database\ModelIdentifier))
#3 [internal function]: App\Jobs\ProcessListing->__wakeup()
#4 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(42): unserialize('O:23:"App\Jobs\...')
#5 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(88): Illuminate\Queue\CallQueuedHandler->call(Object(Illuminate\Queue\Jobs\SqsJob), Array)
#6 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(327): Illuminate\Queue\Jobs\Job->fire()
#7 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(277): Illuminate\Queue\Worker->process('sqs', Object(Illuminate\Queue\Jobs\SqsJob), Object(Illuminate\Queue\WorkerOptions))
#8 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\SqsJob), 'sqs', Object(Illuminate\Queue\WorkerOptions))
#9 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Worker->daemon('sqs', 'ImportQueue', Object(Illuminate\Queue\WorkerOptions))
#10 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('sqs', 'ImportQueue')
#11 [internal function]: Illuminate\Queue\Console\WorkCommand->handle()
#12 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#13 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#14 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#15 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#16 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#17 /srv/www/listingnaples.com/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#18 /srv/www/listingnaples.com/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 /srv/www/listingnaples.com/vendor/symfony/console/Application.php(921): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#20 /srv/www/listingnaples.com/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 /srv/www/listingnaples.com/vendor/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 /srv/www/listingnaples.com/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 /srv/www/listingnaples.com/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 {main}

Here is the model:

TempListingNaples

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class TempListingNaples extends Model
{
    protected $table = "rets_property_res_naples";
    protected $hidden = ['created_at', 'updated_at'];
    protected $dates = ['PhotoModificationTimestamp'];
    public $board = "Naples";

    public function __construct(array $attributes = [])
    {
        $this->fillable = \Config::get('master_schema');
        parent::__construct($attributes);
    }
    
    function toArray()
    {
        $temp = parent::toArray();
            if(starts_with($temp['PhotoModificationTimestamp'], '-'))
            {
                $temp['PhotoModificationTimestamp'] = '0000-00-00 00:00:00';
            }
        return $temp;
    }
}

Console Command

<?php
namespace App\Console\Commands;

use DB;
use App\Models\Listing;
use App\Models\ListingMigrator;
use App\Models\TempListingNaples;
use App\Models\RetsFeed;
use Illuminate\Console\Command;

class MigrateListings extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'chores:MigrateListings';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Migrate the listings from each boards temp table to rets_property_res_mstr';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // Turn off query logging
        DB::connection()->disableQueryLog();

        // get each feed so we can assign models
        $feeds = RetsFeed::where('active', '=', 1)->get();

        foreach ($feeds as $feed)
        {

            // Define which model to use based on the feed's board using the fully qualified namespace
            $class = 'App\Models\TempListing' . $feed->board;

            // Get the listings sitting in the temp table for that board
            $listings = $class::orderBy('MatrixModifiedDT','asc')->get();

            $listings->each(function($listing) use ($feed) {
                \App\Jobs\ProcessListing::dispatch($listing, $feed);
            });

        }
    }
}

Please sign in or create an account to participate in this conversation.