ResourceRepositoryEloquent.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Repositories\Eloquent;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use Prettus\Repository\Eloquent\BaseRepository;
  5. use Prettus\Repository\Criteria\RequestCriteria;
  6. use App\Contracts\Repositories\ResourceRepository;
  7. use App\Repositories\Models\Base\Resource;
  8. use App\Repositories\Validators\ResourceValidator;
  9. /**
  10. * Class ResourceRepositoryEloquent.
  11. *
  12. * @package namespace App\Repositories\Eloquent;
  13. */
  14. class ResourceRepositoryEloquent extends BaseRepository implements ResourceRepository
  15. {
  16. /**
  17. * Specify Model class name
  18. *
  19. * @return string
  20. */
  21. public function model()
  22. {
  23. return Resource::class;
  24. }
  25. /**
  26. * Boot up the repository, pushing criteria
  27. */
  28. public function boot()
  29. {
  30. $this->pushCriteria(app(RequestCriteria::class));
  31. }
  32. public function insertResource($path, $name, $original_name, $url, $size = 0, $disk = 'public', $status = ModelStatusEnum::OK)
  33. {
  34. $this->model->path = $path;
  35. $this->model->name = $name;
  36. $this->model->original_name = $original_name;
  37. $this->model->url = $url;
  38. $this->model->disk = $disk;
  39. $this->model->size = $size;
  40. $this->model->status = $status;
  41. $this->model->saveOrFail();
  42. return $this->model;
  43. }
  44. }