rinvex / laravel-repositories

⚠️ [ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
https://rinvex.com
MIT License
668 stars 115 forks source link

Fix scope #189

Open ruchengtang opened 5 years ago

ruchengtang commented 5 years ago
$this->ofInput('name', $searchData, 'and', true)
    ->ofInput('cellphone', $searchData, 'and', true)
    ->findAll();

Custom base model method:

    /**
     * Search from request input.
     *
     * @param Builder $query
     * @param string $field
     * @param string|array $value
     * @param string $boolean
     * @param bool $like
     *
     * @return Builder
     */
    public function scopeOfInput($query, $field, $value, $boolean = 'and', $like = false)
    {
        if (is_array($value) && !isset($value[$field])) {
            return $query;
        }

        return $this->_where($query, $field, $value[$field], $boolean, $like);
    }
codeclimate[bot] commented 5 years ago

Code Climate has analyzed commit 60a37b87 and detected 0 issues on this pull request.

View more on Code Climate.