HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/komma.pro/app/KommaApp/Kms/Core/Entities/EntityRepository.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\KommaApp\Kms\Core\Entities;

abstract class EntityRepository {

    /**
     * The Eloquent User Object.
     *
     * @var KmsEntity
     */
    public $model;

    /**
     * Constructor.
     *
     * @param KmsEntity $users
     */
    function __construct(KmsEntity $model)
    {
        $this->model = $model;
    }

    public function findAll()
    {
        return $this->model->all();
    }

    public function find($id)
    {
        return $this->model->find($id);
    }

    public function fill(array $data, $id = null)
    {
        if($id != null){
            $entity = $this->find($id);
            return $entity->fill($data);
        }
        return $this->model->newInstance($data);
    }

    public function validationForCreate(array $data)
    {
        $entity = $this->model->newInstance($data);
        return $entity->validateAttributes();
    }

    public function validationForUpdate($id, array $data)
    {
        $entity = $this->find($id);
        $entity->fill($data);
        return $entity->validateAttributes();
    }

    public function create(array $data)
    {
        $entity = $this->model->newInstance($data);
        $entity->save();
        return $entity;
    }

    public function update($id, array $data)
    {
        $entity = $this->find($id);
        $entity->fill($data)->save();
        return $entity;
    }

    public function destroy($id)
    {
        return $this->model->destroy($id);
    }

}