2019-09-12 20:03:56 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use App\Models\Author;
|
|
|
|
|
use App\Models\Language;
|
|
|
|
|
use App\Models\Tag;
|
|
|
|
|
use App\Models\Platform;
|
2020-04-10 06:35:55 +03:00
|
|
|
|
use App\Events\GameSaving;
|
2019-09-12 20:03:56 +03:00
|
|
|
|
|
|
|
|
|
class Game extends Model
|
|
|
|
|
{
|
2019-11-30 08:08:17 +02:00
|
|
|
|
protected $table = 'games';
|
|
|
|
|
public $guarded = ['id'];
|
2019-09-12 20:03:56 +03:00
|
|
|
|
|
2020-04-10 06:35:55 +03:00
|
|
|
|
/**
|
|
|
|
|
* The "booted" method of the model.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::saving(function ($game) {
|
|
|
|
|
// Replace non-breaking space with regular one
|
|
|
|
|
$game->title = str_replace(' ', ' ', $game->title);
|
|
|
|
|
$game->title = trim($game->title);
|
2020-04-10 07:01:09 +03:00
|
|
|
|
// strip quotes
|
|
|
|
|
$game->title = trim($game->title,'"');
|
|
|
|
|
$game->title = trim($game->title,"'");
|
2020-04-10 06:35:55 +03:00
|
|
|
|
$game->description = str_replace(' ', ' ', $game->description);
|
|
|
|
|
$game->description = trim($game->description);
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-09-12 20:03:56 +03:00
|
|
|
|
|
2020-04-10 06:35:55 +03:00
|
|
|
|
public function authors() {
|
|
|
|
|
return $this->belongsToMany(Author::class, 'authors_games');
|
|
|
|
|
}
|
2019-09-12 20:03:56 +03:00
|
|
|
|
|
2020-04-10 06:35:55 +03:00
|
|
|
|
public function languages() {
|
|
|
|
|
return $this->belongsToMany(Language::class, 'languages_games');
|
|
|
|
|
}
|
2019-09-12 20:03:56 +03:00
|
|
|
|
|
2020-04-10 06:35:55 +03:00
|
|
|
|
public function tags() {
|
|
|
|
|
return $this->belongsToMany(Tag::class, 'tags_games');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function platforms() {
|
|
|
|
|
return $this->belongsToMany(Platform::class, 'games_platforms', 'game_id', 'platform_id');
|
|
|
|
|
}
|
2019-09-12 20:03:56 +03:00
|
|
|
|
}
|