belongsToMany(Game::class, 'games_platforms', 'platform_id'); } public static function findByName($name, $autocreate = true) { $model = self::whereRaw('LOWER(title) = ?', mb_strtolower($name))->first(); if (empty($model) && $autocreate) { $model = new self; $model->title = $name; $model->save(); } return $model; } }