Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

global variable in controller laravel 5.3

Tags:

laravel-5.3

How can definition a global variable for use in all function controller

class TestController extends Controller
{
    private $x;

    public function index()
    {
        $this->$x ='22';
    }            

    public function send_message()
    {
        echo $this->$x;
    }
}
like image 437
lock Avatar asked Nov 28 '22 02:11

lock


1 Answers

Write $this->x rather than $this->$x

class TestController extends Controller
{
    private $x;

    public function index()
    {
        $this->x ='22';
    }

    public function send_message()
    {
        echo $this->x;
    }
}
like image 141
Sovon Avatar answered Dec 06 '22 08:12

Sovon