How to use shared variable in Laravel PHP -


 class xyzcontroller extends controller  {      public $a;    public function index(request $request){            $input =request::all();            print_r($input);            $this->a =$input;             return view('page_name', compact('array_name'));    }     public function abc(){           print_r($this->a);    } } 

my code in laravel looks this. it's not working. want use variable in function abc() initialized in function index(). here variable $a public type , initialized in function index() $this->a =$input; , accessing in function abc() print_r($this->a); can not call function index() in function abc() it's returning other pages, while function abc returning other pages different index().

can correct me goes wrong in accessing variable $a in function abc() or can suggest me better way access $a in function without using global variable?

do this:

class xyzcontroller extends controller {      public function index(request $request){      $input =request::all();      session()->put('requestdata',$input);      print_r($input);       return view('page_name', compact('array_name'));    }     public function abc(){      print_r(session('requestdata'));    } } 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -