John Davidson

php - laravel eloquent model record not fetched

0 comments
Message:


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:


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.



My Answer:
"id": 1,
"number": "1234567890",
"type": "mobile",
"created_at": "2021-10-01T12:00:00",
"updated_at": "2021-10-01T12:00:00"
}]

But when I try to fetch a specific record using NumberConfiguration::find(1), I get null as the result. I have checked the database and the record with id 1 exists. Can anyone help me understand why this might be happening?

Rate this post

3 of 5 based on 1365 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us