Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use exists() or doesntExist() method #789

Open
playerarm123 opened this issue Mar 1, 2023 · 1 comment
Open

how to use exists() or doesntExist() method #789

playerarm123 opened this issue Mar 1, 2023 · 1 comment

Comments

@playerarm123
Copy link

I've tried this below code and exists() method doesn't seem to exist in repository
$playerRepo->findByField('username','test001')->exists()
i need to make custom method in repository for determining if records exists.
is there a solution for me ?

@mCassy
Copy link

mCassy commented Jul 10, 2023

@playerarm123

You can implement your own Base repository class with the exists() method e.g

abstract class BaseRepository extends \Prettus\Repository\Eloquent\BaseRepository
{
    public function exists()
    {
        $this->applyCriteria();
        $this->applyScope();
        $model = $this->model->exists();
        $this->resetModel();
        return $this->parserResult($model);
    }
}

And then in your specific repository, you can extend this class and there you go!
Hope that helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants