Queries with Eloquent

0

How can I make a query with eloquent using Like and relate to another table? -

What happens is that I'm looking for a profile of a user according to their skills and specialty, I do not know if it was the best way to do it, but it works for me. but there are certain data that he returns to me that he would not have to give me. because one more condition is missing, in Mysql I would do it with join and all perfect, but I know that eloquent offers me something more elegant. That's where I have the doubt

because I'm looking in the Profile table for those characteristics of each column, each profile belongs to an account.

In summary: I would like to show all the matches of those skill and specialty columns in the Profile table, but as long as the table counts in its Type column it is equal to = 'teacher':

Returning the account information with your respective profile.

(I already have my relationships, I just need the consultation)

I have it this way, but as I said, it only returns the profile and not its condition as an account type.

  $busqueda = profile::where('skills','LIKE','%'.$tags.'%')
                   ->orWhere('especialidad','LIKE','%'.$tags.'%')
                   ->limit(15)->get();
    
asked by Alex Burke Cooper 08.04.2018 в 21:15
source

1 answer

0

then I achieved it this way:

$busqueda = profile::join('Users','users.id','=','profiles.user_id')
        
                    ->where(function($query) use ($tags){
                       $query->where('profiles.skills','LIKE','%'.$tags.'%')
                       ->orWhere('profiles.especialidad','LIKE','%'.$tags.'%')
                    })
                    ->where('users.role','=','profesor')
                    ->with('user')
                    ->limit(15)
                    ->distinct()
                    ->get();
      

   return view('proyectos.buscar',compact('busqueda'));
    
answered by 09.04.2018 в 00:58