Simple search

Posted 3 months ago by eriktobben

Hi,

I am wondering if this query will scope the search result on company_id and not show addresses for a different company?

if ($search) {
    $addresses = Address::where('company_id', auth()->user()->company_id)
    ->where('name', 'LIKE', '%'.$search.'%')
    ->orWhere('address', 'LIKE', '%'.$search.'%')
    ->orWhere('address2', 'LIKE', '%'.$search.'%')
    ->orWhere('zip', 'LIKE', '%'.$search.'%')
    ->orWhere('city', 'LIKE', '%'.$search.'%')
    ->paginate(30);
}

Based on testing it is working, but I am not sure if this query could return addresses which do not belong to the company.

Or is there a better way of doing this?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.