TemplateProgramDetailRepositories.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Repositories;
  3. use App\Model\TemplateProgram as model;
  4. class TemplateProgramDetailRepositories
  5. {
  6. private $model;
  7. public function __construct(model $model)
  8. {
  9. $this->model = $model;
  10. }
  11. public function get(){
  12. return $this->model->where('deleted_at', null)->get();
  13. }
  14. public function getById($id){
  15. $program = $this->model->with('itemProgram','templateProgramRole')->find($id);
  16. return $program;
  17. }
  18. public function save($data){
  19. $save = new $this->model;
  20. $save->nama = $data['nama'];
  21. $save->status = $data['status'] ? $data['status'] : 1;
  22. $save->created_by = $data['created_by'];
  23. $save->logo = $data['logo'];
  24. $save->save();
  25. return $save->fresh();
  26. }
  27. public function update($id, $data){
  28. $db = new $this->model;
  29. $getData = $db->where('id', $id);
  30. $getData->update($data);
  31. return $getData->first();
  32. }
  33. public function delete($id){
  34. $db = new $this->model;
  35. $getData = $db->where('id', $id);
  36. $getData->update(['deleted_at' => date("Y-m-d h:i:s")]);
  37. // $getData->delete();
  38. return $getData->first();
  39. }
  40. }