Boilerplate to use a Directus Instance to Build a Custom Website, Content will be Manage by Directus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

3 years ago
3 years ago
  1. <?php
  2. namespace App\Repositories;
  3. use App\Repositories\RepositoryAbstract;
  4. /**
  5. * request pages items from directus
  6. *
  7. * @author Björn Hase, Tentakelfabrik
  8. * @license http://opensource.org/licenses/MIT The MIT License
  9. * @link https://gitea.tentakelfabrik.de/Tentakelfabrik/super-gear-directus
  10. *
  11. */
  12. class PageRepository extends RepositoryAbstract
  13. {
  14. /** endpoint */
  15. protected $endpoint = 'pages';
  16. /**
  17. * find single page with a slug,
  18. * page must be published
  19. *
  20. * @param string $slug
  21. * @return array
  22. */
  23. public function findOneBySlug($slug)
  24. {
  25. // if slug not set, search for empty slug
  26. if (!$slug) {
  27. $slug = [ '_null' => 'true' ];
  28. } else {
  29. $slug = [ '_eq' => $slug ];
  30. }
  31. return $this->queryBuilder
  32. ->fields([
  33. 'title', 'slug', 'content', 'view', 'meta',
  34. 'media_teaser.*',
  35. 'media_hero.*'
  36. ])
  37. ->aliases('template', 'view')
  38. ->filter([
  39. 'status' => 'published',
  40. 'slug' => $slug
  41. ])
  42. ->findOne();
  43. }
  44. }