Update source into github
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
abstract class BaseRepository implements BaseRepositoryInterface
|
||||
{
|
||||
public $model;
|
||||
public function __construct()
|
||||
{
|
||||
$this->setModel();
|
||||
}
|
||||
abstract public function getModel();
|
||||
|
||||
protected function setModel()
|
||||
{
|
||||
$this->model = app()->make($this->getModel());
|
||||
return $this;
|
||||
}
|
||||
public function create(array $data = [])
|
||||
{
|
||||
return $this->model->create($data);
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
return $this->model->all();
|
||||
}
|
||||
public function find($id)
|
||||
{
|
||||
return $this->model->find($id);
|
||||
|
||||
}
|
||||
|
||||
public function insert(array $data = [])
|
||||
{
|
||||
return $this->model->insert($data);
|
||||
}
|
||||
|
||||
public function update(int $id = 0, array $data = [])
|
||||
{
|
||||
|
||||
$result = $this->find($id);
|
||||
|
||||
if ($result) {
|
||||
$result->update($data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$result = $this->find($id);
|
||||
if ($result) {
|
||||
$result->delete();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public function getCount()
|
||||
{
|
||||
return $this->model->count('id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user