1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Uema;
use Uema\BaseModel;
class BaseRepository
{
protected $model;
public function __construct(BaseModel $model)
{
$this->model = $model;
}
public function create(array $data)
{
return $this->model->create($data);
}
public function update(array $data, $id, $attribute = null)
{
if (!$attribute) {
$attribute = $this->model->getKeyName();
}
$collection = $this->model->where($attribute, '=', $id)->get();
if ($collection) {
foreach ($collection as $obj) {
$obj->fill($data)->save();
}
return $collection->count();
}
return false;
}
public function delete($id)
{
return $this->model->destroy($id);
}
public function all()
{
return $this->model->all();
}
public function lists($identifier, $field, $sort = 'desc')
{
return $this->model->orderBy($identifier, $sort)->pluck($field, $identifier);
}
public function find($id) {
return $this->model->find($id);
}
}