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/Tag.php

37 lines
778 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Language;
use App\Models\Game;
class Tag extends Model
{
public $timestamps = false;
public function language() {
return $this->belongsTo(Language::class);
}
public function games() {
return $this->belongsToMany(Game::class, 'tags_games');
}
/**
* @param string $name
* @param int|Language $language
*/
public static function findByName($name, $language) {
$language_id = NULL;
if ($language instanceof Language) {
$language_id = $language->id;
}
if (is_int($language)) {
$language_id = $language;
}
return self::whereRaw('LOWER(title) = ?', mb_strtolower($name))
->where('language_id', $language_id)
->first();
}
}