<?php

namespace App\Repositories;

abstract class Repository
{
    protected $model;

    public function findId($with = null, $id = null)
    {
        return $this->model
            ->when($with, function ($query) use ($with) {
                return $query->with($with);
            })
            ->when($id, function ($query) use ($id) {
                return $query->where('id', $id);
            })
            ->first();
    }

    public function store($request)
    {
        $request['userid_created'] = auth()->user()->id;

        return $this->model->create($request);
    }

    public function update($request, $model)
    {
        $request['userid_updated'] = auth()->user()->id;

        return $model->update($request);
    }

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