WallRepository.php 976 Bytes
<?php

namespace FootyRoom\Repositories;

use FootyRoom\Core\Wall\Wall;
use FootyRoom\Support\AutoMapper;
use Illuminate\Database\Connection;

class WallRepository
{
    /**
     * @var \Illuminate\Database\Connection
     */
    protected $mysql;

    /**
     * Constructor.
     *
     * @param \Illuminate\Database\Connection $mysql
     */
    public function __construct(Connection $mysql)
    {
        $this->mysql = $mysql;
    }

    /**
     * Finds wall by userId.
     *
     * @param int $userId
     *
     * @return \FootyRoom\Core\Wall\Wall|null
     */
    public function findByUserId($userId)
    {
        $postDto = $this->mysql

        ->table('fr_users')
        ->select([
            'user_id as userId',
            'username',
        ])
        ->where('user_id', '=', $userId)
        ->first();

        if (!$postDto) {
            return null;
        }

        $post = AutoMapper::map($postDto, Wall::class);

        return $post;
    }
}