Normalize games on saving
This commit is contained in:
parent
50cc2e990e
commit
bd9dc69401
|
@ -21,15 +21,20 @@ class Game extends Model
|
|||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
static::saving(function ($game) {
|
||||
static::saving(function (Game $game) {
|
||||
// Replace non-breaking space with regular one
|
||||
$game->title = str_replace(' ', ' ', $game->title);
|
||||
$game->title = str_replace([' ',' '], ' ', $game->title);
|
||||
$game->title = preg_replace('/\s+/', ' ', $game->title);
|
||||
$game->title = trim($game->title);
|
||||
// strip quotes
|
||||
$game->title = trim($game->title,'"');
|
||||
$game->title = trim($game->title,"'");
|
||||
$game->description = str_replace(' ', ' ', $game->description);
|
||||
$game->description = trim($game->description);
|
||||
if (isset($game->description)) {
|
||||
$game->description = $game->normalizeDescription($game->description);
|
||||
}
|
||||
if (isset($game->short_description)) {
|
||||
$game->short_description = $game->normalizeDescription($game->short_description);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -74,6 +79,7 @@ class Game extends Model
|
|||
}
|
||||
|
||||
public function normalizeDescription($description) {
|
||||
$description = str_replace(' ', ' ', $description);
|
||||
$description = str_replace('...','…',$description);
|
||||
$description = str_replace('\r','',$description);
|
||||
$description = str_replace(['<br>', '<br/>', '<br />'], "\n", $description);
|
||||
|
|
Reference in a new issue