Custom aliases and casts for post meta not working
- Dominant language
- PHP
- Stars
- 4.8k
- Forks
- 600
- PR merge metrics
- No merged PRs in 30d
Description
- Corcel Version: 5.0
- Framework Name & Version: Laravel 8
- PHP Version: 8.0
- Database Driver & Version: MariaDB 10.6
### Description:
When defining the `$aliases` on a custom model, the meta fields aren't loaded correctly and the `$casts` seem to be ignored.
~~(On a side note, default post aliases don't seem to be inherited correctly, like `title` or `slug` etc. I need to define them all as well.)~~ **Fixed** by adding `use Corcel\Concerns\Aliases;` to custom model.
Setting the meta data keys in `$appends` works correctly, but the `$aliases` seem to be ignored.
Maybe I'm missing something here?
### Steps To Reproduce:
1. Create a custom model and extend `Corcel\Model\Post`
2. Add a custom meta field called `channel_failures` and set it to a value of `10`.
2. Define a custom meta field in `$appends` and make an alias in `$aliases`, add field to `$casts`.
```php
protected $casts = [
'failures' => 'int', // doesn't work
'channel_failures' => 'int', // doesn't work
];
protected $appends = [
'failures', // doesn't work
'channel_failures', // works
];
protected static $aliases = [
'failures' => 'channel_failures', // doesn't work
];
```
3. Try it and see that it doesn't work as expected:
```php
MyPostType::first()->failures; // null
MyPostType::first()->channel_failures; // "10" <- not being cast to int
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.