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
Raw Permalink Normal View History

2019-09-12 20:03:56 +03:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\Language;
use App\Models\Game;
class Tag extends Model
{
2019-11-30 09:03:43 +02:00
public $timestamps = false;
2019-09-12 20:03:56 +03:00
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
*/
2020-10-21 07:48:00 +03:00
public static function findByName($name, $language) {
$language_id = NULL;
if ($language instanceof Language) {
$language_id = $language->id;
}
if (is_int($language)) {
$language_id = $language;
}
2020-10-21 09:45:37 +03:00
return self::whereRaw('LOWER(title) = ?', mb_strtolower($name))
->where('language_id', $language_id)
2020-10-21 09:45:37 +03:00
->first();
2020-10-21 07:48:00 +03:00
}
2019-09-12 20:03:56 +03:00
}