26 lines
556 B
PHP
26 lines
556 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use App\Models\Game;
|
|
|
|
class Platform extends Model
|
|
{
|
|
public $timestamps = false;
|
|
|
|
public function games() {
|
|
return $this->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;
|
|
}
|
|
}
|