例:
public function setSomFieldAttribute($value) { return $this->attributes['some_field'] = trim($value); }
例:
public function setSomFieldAttribute($value) { return $this->attributes['some_field'] = trim($value); }
<?PHP class Post extends Eloquent { protected function getAttributeValue($key) { $value = parent::getAttributeValue($key); return is_string($value) ? trim($value) : $value; } public function setAttribute($key,$value) { parent::setAttribute($key,$value); if (is_string($value)) { $this->attributes[$key] = trim($value); } } }
你永远不应该再获得未经修改的价值.
编辑:
在这里测试过,我没有空格:
Route::any('test',['as' => 'test',function() { $d = Post::find(2); $d->title_en = " Markdown Example "; dd($d); }]);