Global variable in laravel 4

前端 未结 6 549
萌比男神i
萌比男神i 2020-12-07 23:17

I was wondering how to do a global variable to save me few lines of copy and pasting this lines. Array it probably and put them in one variable instead? I want to use this

6条回答
  •  执念已碎
    2020-12-08 00:00

    You should create an object to do that.

    Create a provider object with those properties, email, name, etc and instantiate it and set the properties values, like:

    $provider = new Provider();
    
    $provider->email = Auth::user()->email;
    

    And then you save the object in your session:

    $_SESSION['provider'] = $provider;
    

    I'm not familiar with Laravel and I don't know if it's a good practice to work directly with the Auth object but a simpler solution would be:

    $_SESSION['provider'] = Auth::user();
    

    Also be aware of working with sensitive information on your session :)

提交回复
热议问题