TahunProgramRepositories.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Repositories;
  3. use App\Model\TahunProgram as model;
  4. class TahunProgramRepositories
  5. {
  6. private $model;
  7. public function __construct(model $model)
  8. {
  9. $this->model = $model;
  10. }
  11. public function get($offset, $limit){
  12. // print_r($limit);
  13. // if ($offset == 1) {
  14. // $offset = 0;
  15. // } else {
  16. // $offset = ($offset - 1) * $limit;
  17. // }
  18. return $this->model->offset($offset)->take($limit)->get();
  19. // return $this->model->get();
  20. }
  21. public function getById($id){
  22. $program = $this->model->find($id);
  23. $item = $program->tahunProgram;
  24. // $program['list_program'] = $item;
  25. return $program;
  26. }
  27. public function getCount() {
  28. return $this->model->count();
  29. }
  30. public function save($data){
  31. $save = new $this->model;
  32. $save->label_tahun_program = $data['label'];
  33. $save->value = $data['value'];
  34. $save->status = $data['status'] ? $data['status'] : 1;
  35. $save->created_by = $data['created_by'];
  36. $save->save();
  37. return $save->fresh();
  38. }
  39. public function delete($id){
  40. $db = new $this->model;
  41. $getData = $db->where('id', $id);
  42. $getData->update(['status' => 2]);
  43. // $getData->delete();
  44. return $getData->first();
  45. }
  46. }