【发布时间】:2018-12-19 08:23:09
【问题描述】:
我想在 laravel eloquent 中创建一个函数,从名称中确定参数,例如 whereName() whereAdresse() 。
这个是怎么弄的,谢谢
【问题讨论】:
-
请向我们展示你的努力,我的意思是你的代码?
我想在 laravel eloquent 中创建一个函数,从名称中确定参数,例如 whereName() whereAdresse() 。
这个是怎么弄的,谢谢
【问题讨论】:
你需要像这样编辑 Eloquent 魔术方法 __call():
public function __call($name, $value)
{
if (substr($name, 0, 5) == 'where') {
$this->where(substr($name, 5), $value);
//or try call_user_func([$this, 'where'], array_merge(substr($name, 5), $value));
} else {
parent::__call($name, $value);
}
}
我认为你的欲望是一种不好的欲望 =)
【讨论】: