Description
Last days they answered me in another question that could implement whereHas
to make a query to two different tables. In this case the table noticias
and notas
same that does not let me receive the data in the views of blade.
Driver Function to implement. Error throw:
Parse error: syntax error, unexpected '- >' (T_OBJECT_OPERATOR))
How would the function be correctly implemented so that the search engine finds results from both tables ( notas
and noticias
), to be seen?
public function busqueda(Request $request){
$ntc_turno = $request->input('noticiero_turno');
if ($ntc_turno) {
Noticia::with('notas')->whereHas(
'notas',
function($query) use($ntc_turno) {
$query->where('nombre_nota','LIKE',"%$ntc_turno%");
}
)
->orWhere('noticiero_turno','LIKE',"%$ntc_turno%");
->orWhere('noticiero_programa','LIKE',"%$ntc_turno%");
->orWhere('noticiero_fecha','LIKE',"%$ntc_turno%");
->paginate(2);
return view('noticia.listar',array('noticia'=>$noticia));
}else {
$noticia = Noticia::paginate(3);
return view('noticia.listar',array('noticia'=>$noticia));
}
}
Model: news
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Noticia extends Model
{
protected $fillable = ['noticiero_programa','noticiero_turno','noticiero_fecha'];
public function notas()
{
return $this->hasMany('Nota', 'noticia_id');
}
}
Model: Note
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Nota extends Model
{
protected $fillable = ['nombre_nota', 'editor_nota','duracion_nota', 'bloque_nota', 'noticia_id'];
public function noticias()
{
return $this->BelongsTo('Noticia', 'noticia_id');
// pertenece a
}
}