Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

laravel orm 模型casts 属性字段定义object 写入日志报错 #5

Closed
2512422541 opened this issue Aug 25, 2023 · 2 comments
Closed

Comments

@2512422541
Copy link

laravel 8.x 创建 Test Model 定义 attrs 字段定义成 AsArrayObject

namespace App\Models;

class Test extends Model
{
    protected $fillable = [
        'name',
        'attrs'
    ];

    protected $casts = [
        'attrs' => AsArrayObject::class
    ];
}

使用Test模型写入数据 并查看操作日志记录

\App\Models\Test::create([ 
      'name' => 'testName',
      'attrs' => [ 'id' => 1,
            'val' => 'testVal'
       ]
 ]);

$logStr = \Chance\Log\facades\OperationLog::getLog();

var_dump($logStr);

执行结果
image

找到问题所在 因为字段被定义成了object 在获取字段数据的时候 object 类型 attrs 被强转成(string)会抛错

image

需要兼容下 object 数据类型 也转化一下

@Chance-fyi
Copy link
Owner

我创建了 laravel 8.x 的新项目,没有复现这个问题。你的具体版本号是多少?

@2512422541
Copy link
Author

佬 版本是 laravel 8.83.27 但是跟小版本没有关系 主要是设置了表模型对应关系后,获取日志就会抛这个错
image

Chance-fyi added a commit that referenced this issue Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants