You can probably override these methods:
<?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); } } }
And you should never get the raw value again.
EDIT:
Tested here and I did not get spaces:
Route::any('test', ['as' => 'test', function() { $d = Post::find(2); $d->title_en = " Markdown Example "; dd($d); }]);
source share