Laravel (5.4) Parse error: syntax error, unexpected '-' (T_OBJECT_OPERATOR)

2

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
    }
}
    
asked by CARLOS OMAR BLANCO RODRÍGUEZ 08.04.2018 в 20:36
source

1 answer

4

Your problem is the ones; that are left over at the end of each line of orWhere :

->orWhere('noticiero_turno','LIKE',"%$ntc_turno%")
->orWhere('noticiero_programa','LIKE',"%$ntc_turno%")
->orWhere('noticiero_fecha','LIKE',"%$ntc_turno%")
->paginate(2);
    
answered by 08.04.2018 / 20:48
source