Return two a variable in two views

0

I have a view called show, to which I want to put a select, defined in the variable $ usersOptions, the problem is that this variable only returns to user.index, there is some way that you can also return it to user .show?

/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $usuarios=usuarios::orderBy('id','DESC')->paginate(10);
        $usuariosOpciones =usuarios::pluck('usuario_ad', 'user_id')->unique();
        return view('usuario.index',compact('usuarios','usuariosOpciones')); 

    }
    
asked by zereft 16.10.2018 в 03:53
source

1 answer

0

What you can do is create a new method:

public function usuariosOpciones(){
    return usuarios::pluck('usuario_ad', 'user_id')->unique();
}

Then you simply call the method usuariosOpciones()

public function index(){
  $usuariosOpciones = $this->usuariosOpciones();
}

And in your method show you would do the same:

public function show($id){
  $usuariosOpciones = $this->usuariosOpciones();
}
    
answered by 16.10.2018 / 05:03
source