Laravel afterFind回调事件 [英] Laravel afterFind Callback Events

查看:116
本文介绍了Laravel afterFind回调事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在laravel中是否有如cakePHP中的afterFind()模型事件,因此我可以在任何搜索查询之后格式化数据.或其他任何方式?

Is there any afterFind() Model Event in laravel as in cakePHP so that I can format the data after any search query. or any other way to do that ?

谢谢

推荐答案

这不是事件,而是可以在模型中设置的变量.您只需在模型中创建一个名为setFooAttribute($value)的方法,其中Foo是要在camelCase中修改的列的名称.

It's not an event, but a mutator you can set in your model. You simply create a method in your model named setFooAttribute($value) where Foo is the name of the column you want to modify in camelCase.

示例:

public function setFirstNameAttribute($value)
{
    $this->attributes['first_name'] = strtolower($value);
}

这是正确的文档,如此处所示... http://laravel. com/docs/eloquent#accessors-and-mutators

This is right from the documentation as seen here... http://laravel.com/docs/eloquent#accessors-and-mutators

这篇关于Laravel afterFind回调事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆