Archived
1
0
Fork 0
This repository has been archived on 2021-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
ifnews/app/Models/Platform.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;
}
}