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

Change Columns and Joins Dynamically [SOLVED] #208

Open
trijulio opened this issue Feb 2, 2020 · 0 comments
Open

Change Columns and Joins Dynamically [SOLVED] #208

trijulio opened this issue Feb 2, 2020 · 0 comments

Comments

@trijulio
Copy link

trijulio commented Feb 2, 2020

If you want to change the columns to search on the same model, you can do it dynamically inserting this code to your model or to the source file:

vendor/nicolaslopezj/searchable/src/SearchableTrait.php

    public function scopeSetSearchScope($query,$search = []){
        $this->searchable = $search;
        return $query;
    }

Then you can:

        $toSearch = [
            'columns' => [
                'contacts.name' => 10,
                'contacts.last_name' => 10,
                'contacts.alias' => 10,
                'fields.value' => 5,
            ],
            'joins' => [
                'fields' => ['contacts.id','fields.contact_id'],
            ],
        ];

        $contacts =  Contact::with(['fields'])
                    ->companyScope()
                    ->setSearchScope($toSearch)
                    ->search(request('search'),null,true)
                    ->groupBy('contacts.id')
                    ->orderBy('relevance','desc')
                    ->paginate(request('show',100));
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

1 participant