The problem search field is working, but I would like to search for the client name as they are related.
search method in controller
public function busca(OrdemRequest $request)
{
$problema = $request->problema;
$ordens = Ordem::where('problema', 'LIKE', "%{$problema}%")->get();
return view('ordem.listaordens',compact('ordens'));
}
Route:
Route::post('/busca','OrdemController@busca');
View:
<form action="/ordem/busca"method="post">
<div class="form-group">
{{csrf_field()}}
<input type="text" class="form-control" name="problema" placeholder="Buscar...">
Order Model:
class Ordem extends Model
{
protected $fillable = ['id','cliente_id','valor','data','problema','servico_id'];
protected $table = 'ordens';
public function produto()
{
return $this->belongsToMany(produto::class, 'produto_id');
}
public function servico()
{
return $this->belongsTo(servico::class,'ordem_id','servico_id');
}
public function cliente()
{
return $this->belongsTo(Cliente::class,'cliente_id');
}
}
Client Model:
class Cliente extends Model
{
protected $fillable = ['id','nome','cpf','endereco','telefone','email'];
protected $table = 'clientes';
public function ordem()
{
return $this->hasMany(ordem::class,'cliente_id');