BaseRepository.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace app\common\repositories;
  3. /**
  4. * Interface CoreRepository
  5. * @package app\common\repositories
  6. */
  7. interface BaseRepository
  8. {
  9. /**
  10. * @param int $id
  11. * @return $model
  12. */
  13. public function find($id);
  14. /**
  15. * Return a collection of all elements of the resource
  16. * @return \Illuminate\Database\Eloquent\Collection
  17. */
  18. public function all();
  19. /**
  20. * Paginate the model to $perPage items per page
  21. * @param int $perPage
  22. * @return \Illuminate\Pagination\LengthAwarePaginator
  23. */
  24. public function paginate($perPage = 15);
  25. /**
  26. * Create a resource
  27. * @param $data
  28. * @return $model
  29. */
  30. public function create($data);
  31. /**
  32. * Update a resource
  33. * @param $model
  34. * @param array $data
  35. * @return $model
  36. */
  37. public function update($model, $data);
  38. /**
  39. * Destroy a resource
  40. * @param $model
  41. * @return bool
  42. */
  43. public function destroy($model);
  44. /**
  45. * Return resources translated in the given language
  46. * @param string $lang
  47. * @return \Illuminate\Database\Eloquent\Collection
  48. */
  49. public function allTranslatedIn($lang);
  50. /**
  51. * Find a resource by the given slug
  52. * @param string $slug
  53. * @return $model
  54. */
  55. public function findBySlug($slug);
  56. /**
  57. * Find a resource by an array of attributes
  58. * @param array $attributes
  59. * @return $model
  60. */
  61. public function findByAttributes(array $attributes);
  62. /**
  63. * Return a collection of elements who's ids match
  64. * @param array $ids
  65. * @return \Illuminate\Database\Eloquent\Collection
  66. */
  67. public function findByMany(array $ids);
  68. /**
  69. * Get resources by an array of attributes
  70. * @param array $attributes
  71. * @param null|string $orderBy
  72. * @param string $sortOrder
  73. * @return \Illuminate\Database\Eloquent\Collection
  74. */
  75. public function getByAttributes(array $attributes, $orderBy = null, $sortOrder = 'asc');
  76. /**
  77. * Clear the cache for this Repositories' Entity
  78. * @return bool
  79. */
  80. public function clearCache();
  81. }