Laravel 4:Getter和Setter方法

mwa*_*afi 4 php laravel laravel-4

我试图让Getter&Setter Methods工作(来自Laravel 4中的Laravel 3)

但显示错误.

这附近有什么工作吗?

它们在密码案例中非常有用:

public function set_password($password)
{
    $this->set_attribute('hashed_password', Hash::make($password));
}
Run Code Online (Sandbox Code Playgroud)

http://three.laravel.com/docs/database/eloquent

mwa*_*afi 9

刚刚找到答案:

现在它称为Accessors&Mutators

https://laravel.com/docs/5.2/eloquent-mutators

在设置之前哈希密码:

public function setPasswordAttribute($pass)
{
    $this->attributes['password'] = Hash::make($pass);
}
Run Code Online (Sandbox Code Playgroud)