60 lines
1.4 KiB
PHP
60 lines
1.4 KiB
PHP
<?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;
|
||
use App\Events\GameSaving;
|
||
|
||
class Game extends Model
|
||
{
|
||
protected $table = 'games';
|
||
public $guarded = ['id'];
|
||
|
||
/**
|
||
* 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);
|
||
// strip quotes
|
||
$game->title = trim($game->title,'"');
|
||
$game->title = trim($game->title,"'");
|
||
$game->description = str_replace(' ', ' ', $game->description);
|
||
$game->description = trim($game->description);
|
||
});
|
||
}
|
||
|
||
public function authors() {
|
||
return $this->belongsToMany(Author::class, 'authors_games');
|
||
}
|
||
|
||
public function languages() {
|
||
return $this->belongsToMany(Language::class, 'languages_games');
|
||
}
|
||
|
||
public function tags() {
|
||
return $this->belongsToMany(Tag::class, 'tags_games');
|
||
}
|
||
|
||
public function platforms() {
|
||
return $this->belongsToMany(Platform::class, 'games_platforms', 'game_id', 'platform_id');
|
||
}
|
||
|
||
public function printShort() {
|
||
echo _('Title').': '.$this->title.PHP_EOL;
|
||
}
|
||
|
||
public function printDetailed() {
|
||
$this->printShort();
|
||
}
|
||
}
|