TeamRepository.php 1 KB
<?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();
    }
}