Is not the attribute assigned to me in laravel lumen?

0

I am trying to call the attribute but it gives me as null if I call it from another function, does anyone know that it may be happening?

 class ArchivoController extends Controller
 {

 public $usuario;

 function pasar(Request $request)

 {


  $data = $request->json()->All();

  $this->usuario = $data;     //si pongo debajo dd($this->usuario); me da 
                              // los datos correctos



  }


  function ver()
  {

  dd($this->usuario);   //<---- me da null cuando me debería dar los datos 
                        //      que le he asignado arriba


  }



  }
    
asked by ortiga 16.03.2018 в 15:35
source

1 answer

1

What happens is that you are not returning any value.
You are missing the return in the 2 methods.

class ArchivoController extends Controller
{
    public $usuario;

    function pasar(Request $request)
    {
        $data = $request->json()->All();

        $this->usuario = $data;     //si pongo debajo dd($this->usuario); me da 
                                    // los datos correctos
        return $this->usuario;
    }

    function ver()
    {
        // dd($this->usuario);   //<---- me da null cuando me debería dar los datos 
        //      que le he asignado arriba
        return $this->usuario;
    }
 }
    
answered by 16.03.2018 / 16:23
source