-1

I have 4 tables in my DB. User , user_details, tags and taggables. By using the user table I am getting user along with user detail and tags. Following is table schema

Table user:
id, name, email, password

Table user_details
user_id, about, vision, picture

Table tags:
id, name

Table taggables
user_id, tag_id

here is my query:
User::with('userDetails','tags')->get();

I want to use where like in user name or tag name, How can I use multiple where like on user name and tag name????

Haris Khan
  • 15
  • 3

1 Answers1

0

Do you want something like this?

$users= User::with('userDetails','tags')
            ->where('name', 'LIKE',"%{$search}%")
            ->orWhereHas('tags', function($query) use($search) {
                $query->where('name','LIKE',"%{$search}%");
            })
            ->get();

$search is a variable here.

zahid hasan emon
  • 6,023
  • 3
  • 16
  • 28