Sunday, February 8, 2015

Creating default object from empty value in PHP

Add this to BaseController

$identity = Auth::user();

if (!isset($identity)) $identity = new stdClass();

Then throughout the laravel program user->info can be accessed with identity->info instead of constantly Auth::user->info




No comments:

Post a Comment