Pass a variable to a view with laravel 5.6

1

Good evening I'm using laravel 5.6, and I have a doubt I want to pass a variable to my view in order to use it and help me define whether or not to insert a form in view in the controller I have the following code:

public function listar($dato=""){
               if ($dato="pendiente") {
        $LlamadaDetectar=true;
        $asignacion=DB::table('asignacions')
        ->join('rangos','funcionarios.id_rango','=','rangos.id_rango')
        ->join('almacens','asignacions.id_almacen','=','almacens.id_almacen')
        ->select('id_asignacion','rangos.abreviacion AS grado','almacens.descripcion AS Oficina','asignacions.estado AS estadoAsignacion')
        ->where('asignacions.estado','=', 1)
        ->where('almacens.almacen_padre','=', $almaceUsuario)->paginate(25);
    }
    elseif($dato=""){
        $LlamadaDetectar=false;
        $asignacion=DB::table('asignacions')
        ->join('rangos','funcionarios.id_rango','=','rangos.id_rango')
        ->join('almacens','asignacions.id_almacen','=','almacens.id_almacen')
        ->select('id_asignacion','rangos.abreviacion AS grado','almacens.descripcion AS Oficina','asignacions.estado AS estadoAsignacion')
        ->where('almacens.almacen_padre','=', $almaceUsuario)->paginate(25);
    }
   }
    return view('material.asignaciones',compact('asignacion'))->with('LlamadaDetectar', $LlamadaDetectar);

} 

The variable I'm sending is $ CallDetect = true;

Which I try to use it in my view in the following way:

<h2 class="text-center">Asignaciones de material</h2>
<div class="col-lg-6 offset-lg-3 col-md-12">
 <div class="input-group">
   <?php
   if ($LlamadaDetectar=false) {
     echo "<input type='text' class='form-control' id='buscarAsignacion'>"; 
   }
   ?>
 </div>
</div>
    
asked by ALVARO ROBERTO BACARREZA ARZAB 24.05.2018 в 01:22
source

1 answer

1

If you are going to work with the blade syntax in the Laravel views; which is in fact recommended, then your code should look like this

@if($LlamadaDetectar == false)
    {!! "<input type='text'>" !!}
@endif

With the above you avoid being inserted backend code in pure php, which will keep more order the view file; besides benefitting from blade

On the other hand I tell you that your if is incorrect from the moment you try to verify if a variable is false or true; since you are using only one operator of the same, the thing goes like this

  • = Means equal to a = 9; we are saying that a is equal to 9
  • == It means comparison 10 == 10, it will return true because 10 if it is equal to 10
  • answered by 24.05.2018 / 01:48
    source