1 year ago

Simple search

Posted 1 year ago by eriktobben


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.'%')

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.