簡體   English   中英

laravel eloquent model 記錄未獲取

[英]laravel eloquent model record not fetched

我面臨一個奇怪的問題。 當我執行NumberConfiguration::all()時,我收到以下結果:

[{"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}]  

但在數據庫中我實際上有 2 條記錄: 在此處輸入圖像描述

我沒有發現任何可能導致此問題的原因,並非所有記錄都由 eloquent model 投標表示。 我正在使用 postgresql 數據庫。

父 class 中有一個觀察者,但即使我將其注釋掉,也會出現同樣的問題。

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;
}
}

任何幫助都非常受歡迎。

查看全局范圍。

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

這就是您禁用全局范圍並檢索所有內容的方式。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM