Use method in findBy() …

Hello everyone,

is there any way to use a method in findBy()?

For example, from all children, I’d like to find a project by the slug of it’s title:

findBy('title'->slug(), $slug) where $slug is already defined …

You could create a model with a custom method that returns the title as slug and then use this custom method in your findBy(), or you use filter($callback) and then return the first.

class ProjectPage extends Page {
  public function titleSlug() {
    return $this->title()->slug();
  }
}
$project = $projects->findBy('titleSlug', $slug);
2 Likes

That’s the perfect solution.

Thank you so much, @texnixe.