Home > front end >  laravel eloquent model record not fetched
laravel eloquent model record not fetched

Time:09-13

I am facing a strange issue. When I do NumberConfiguration::all() I receive the following result:

[{"id":1,"created_at":"2022-09-13 09:48:51 0200","updated_at":"2022-09-13 09:49:12 0200","block_start":"41582550003","block_end":"41582550003","number_block_id":1,"special_numbers":null}]  

but in the database I have actually 2 record: enter image description here

I didnt find anything what can cause this problem, that not all record are represented by the eloquent model biding. I am using postgresql database.

There is an observer in the parent class, but even if I comment it out the same problem occurs.

class NumberConfiguration extends BaseConcreteProductConfiguration
{

protected $table = 'shop.numbers_configurations';

// Needs to be present in every ConcreteConfiguration file who has a Observer with action on cart to order
protected $fillable = [ 'updated_at' ];


protected $casts = [ 'special_numbers' => 'array' ];

public static function getValidations(string $prefix = ''): array
{
    return [
        $prefix . 'block_start'     => [ 'nullable' ],
        $prefix . 'block_end'       => [ 'nullable' ],
        $prefix . 'number_block_id' => [ 'nullable', 'numeric' ],
        $prefix . 'special_numbers' => [ 'nullable' ],
    ];
}

public static function getManager(): ConfigurationManagerInterface
{
    return new NumberConfigurationManager();
}

public function getDescription(): ?string
{
    $numberBlock = NumberBlock::find($this->number_block_id);

    if (!is_null($numberBlock)) {
        $numbers = $numberBlock->numbers()->pluck('did');

        if (!empty($numbers)) {
            return NumberManager::groupNumberToDisplayWithLocalPrefix(NumberManager::groupNumbersByRange($numbers))
                ->reduce(fn($a, $b) => $a . $b . ' ');
        } else {
            \Log::warning('configuration description not available, no numbers for block: '
                          . $this->number_block_id);
        }
    }

    return null;
}
}

Any help is higly appriciated.

CodePudding user response:

Check out for global scopes.

NumberConfiguration::withoutGlobalScopes()->get();

This is how you disable global scopes and retrieve everything.

https://laravel.com/docs/9.x/eloquent#writing-global-scopes

  • Related