last day (15 days later) » 

11:56
0
A: Where should I store the Laravel Session data based on the MVC pattern?

TschallackaYou can use the laravel https://laravel.com/docs/5.6/session Session helper. Then you can just do Session::put('hello','world'); Session::save(); and retrieve it with Session::get('hello'); You can do this anywhere you'd like, as long as you remember to save the session after putting things in i...

Thank you for the answer, I've already read the full Session documentation on the Laravel :) The problem, I'd like to know where is the best place to store them. By the way, Session::put('hello','world'); Session::save(); syntax is no longer submitted in the newest Laravel docs you linked :)
@PukaUnknown session()->put() does exactly the same, it calls Session::put under the hood by accessing the static variable. but that's semantics. You call these where-ever you have need for the values stored in the session. In a user authentication module you call it in that module. For a username display you call it in a template or in the controller rendering the template, for a shopping cart, you call it in the shopping cart render module, etc...
By saying module, you mean inside the controller? I would have to load that controller every time, maybe using built-in Service Provider boot function would be a better approach?
You have a controller, that renders several elements. Sometimes you wish to re-use elements, so you build your own render code for it so you can re-use it and then just call $shoppingRender = new ShoppingCartRender(); return $shoppingRender->render(); that's what I call a module. You really don't need to call it in boot() or anywhere just to put it in a static class. The Session class/helper function in itself is static and a singleton and available from EVERYWHERE. Just call it when and where it's needed. Don't overcomplicate things. keep it simple.
Yea, thanks, I simply would like to learn the best practices, so in the future, it's gonna be simple :) But then I'll have to call that controller on boot while using the boot function, I wouldn't need that. Am I right?
11:56
No, as long as laravel is loaded and the session class can read and write variables you can use it anywhere you want.
Where would you put them in my situation? I understand "anywhere you want" but it's not very helpful.
@PukaUnknown you have not shown code or what your execution flow is. First wordpress then laravel? first laravel then wordpress? first generic, then laravel, then wordpress then something else? is laravel used as a helper in a wordpress plugin? does laravel interface with wordpress to get data out? you haven't provided what kind of data you store in session or what you want to do with it. without that information i really can't say much.
Oh, ok, sorry about that. It's the Laravel integrated to the WordPress (but it's a different folder - laravel: prntscr.com/kg5f5e. Inside that folder, you can see a basic file structure of the Laravel: prntscr.com/kg5g3x. It's not a plugin. I've loaded WP functions (wp-load.php file) in the Laravel Service Provider here: prntscr.com/kg5ijm. No fancy stuff here :) The session data I'd like to store is simple. Basic strings and integers :)
@PukaUnknown do you only need the session data in laravel? or do you need the session data in wordpress(running as wordpress instance) as well?
Nice question! :) Yea, I'd need it only for the Laravel. There is a .htaccess file, which redirects to the Laravel public path.
11:56
@PukaUnknown Then you can just go with the Session::get() or session()->get() method without needing hacks to get the values within wordpress as well.
I've been using session('...') to get the value and session(['...' => '...']) to set it but that's just a shortcut. Where should I place session data? I'm sorry if it feels like you've already my question. I'd like to know what's the best way in this situation. Maybe it's very valuable to others but maybe someone here also trying to connect WP with the Laravel and have the same question :) Why putting this data in the Service Provider is bad? Didn't quite understand why it's not a good way? - "I'll have to call that controller on boot while using the boot function, I wouldn't need that."
in your code, where you need it, just do session()->get('yourvariablename')
so give me an actual sample of code where you use session data for something
then I can "show" you
Yea, sure
I've set this session data inside the WP theme header.php file:
session([
    'currentUser' => wp_get_current_user(),
    'user' => session('currentUser')->user_login
]);
It's not a good place because changing the theme will break these session variables.
I'm looking for a way to do it globally.
so, you're running wordpress sessions?
okay,
you don't want it in a theme, because when theme changes it breaks
then you'll need to use wordpress hooks
and register the wordpress action listeners within wordpress to fullfill that rule
and modify the given wordpress template part that's rendered via those action hooks
Not WP session, laravel
I don't wanna get into the WP, the WP is only for the admin panel, + -.
Why can I use it in the service provider?
12:10
okay, but you have a wordpress template
where you don't want to code it in you said
and I assume that's rendered with the wordpress engine
I'm trying to get a grasp of your program layout
and what you're exactly trying to achieve in which framework
I'm quite a newbie to Laravel, not sure where to put things :d
The only global place to put things specially created for that is Service Provider
I could possible to it in the index.php file (of the laravel installation).
That wouldn't be good if I tried to install a new version of it
I'm a bit curious why you think it's a bad idea
Where did u put those session variables when working on the Laravel project?
12:38
Are you here? :(

last day (15 days later) »