how to do a search engine in laravel with related tables

1

hi good morning community today I would like to ask you how to do a scope in Laravel but this is related to other tables, here in the example I'm looking directly only the id of the installer and I need to look for it through the name but when I try to relate it Why does getinstalador give me any advice I can give? you would be grateful

namespace App;

use Illuminate \ Database \ Eloquent \ Model;

class Installer_point extends Model {         protected $ fillable = ['punto_id', 'instalador_id', 'cant_dia', 'fecha_inicio', 'fecha_fin'];

public function getinstalador ()   {

return $ this-> belongsTo (Installer :: class, 'installer_id');

}

public function getpunto ()   {   return $ this-> belongsTo (Point :: class, 'point_id');

}   public function scopeSearch ($ query, $ installer_id)     {       return $ query-> where ('installer_id', 'LIKE', "% $ installer_id%");

}
//

}

public function instaladoresindex(Punto $punto, Request $request)
{

    $instaladores = Instalador_punto::Search($request->instalador_id)->orderBy('id', 'ASC')->paginate(10);




       return view('/puntos/instaladores/instaladoresindex')->with(compact('instaladores','punto'));
    //
}
    id)}} ">     {{csrf_field ()}}                           Search for                                        
asked by Jesus Lopez 28.11.2018 в 15:41
source

1 answer

1

Try it this way:

public function scopeSearch($query, $instalador_id){
    $query->whereHas("getinstalador", function ($query) use ($instalador_id) {
        $query->where('id', $instalador_id);
    });
}

Since you have made the relationships between the models, you can use eloquent to build your queries, in this case using the function whereHas ()

I hope it works for you, it should work.

    
answered by 28.11.2018 в 16:37