TeamRepository.php
1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace FootyRoom\Repositories;
use Illuminate\Database\Connection as MySqlClient;
class TeamRepository
{
/**
* @var \Illuminate\Database\Connection
*/
protected $mysql;
/**
* Constructor.
*
* @param \Illuminate\Database\Connection $mysql
*/
public function __construct(MySqlClient $mysql)
{
$this->mysql = $mysql;
}
/**
* Suggests teams by name.
*
* @param string $name
* @param string $type
* @param string $gender
*
* @return object[] {
* @var int 'team_id'
* @var string 'team_name'
* @var string 'country'
* }
*/
public function suggestTeams($name, $type = 'club', $gender = 'm')
{
return $this->mysql
->table('teams')
->select(['team_id', 'team_name', 'country'])
->where('type', '=', $type)
->where('team_name', 'LIKE', "%$name%")
->where('gender', '=', $gender)
->take(10)
->get();
}
}