Home Laravel initiation of varible in __construct() VS while defining
Reply: 0

Laravel initiation of varible in __construct() VS while defining

Sagynbek Kenzhebaev
1#
Sagynbek Kenzhebaev Published in 2018-02-10 20:09:18Z

I was generally using Laravel __construct() function in Controllers to initialize some parameters. But when I trying to call method via AJAX request, protected variables seem to be not defined in method. I.e.

protected $imageWidth;
public function __construct(){
   $this->imageWidth=500;
}

But when I initialize protected variable, while defining it, it solves my problem.

protected $imageWidth=500;

So, what is the difference between these 2 initializations and which should I use in which cases? Thanks...

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.303123 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO