I have an admin template which I builded with blade templates,including one another.The user request is extending the main blade and returning only the content. However in the template I have stuff like - user messages(count),theme options etc. These things must be saved in the user session.Cookies are not an option. The question is how to do it in the best possible option.
I'm thinking of gettind the request in middleware and accessing the session there.After that I must pass the data to the blade templates (not the final extending one).
Whats your opinion ?! Thanks!
If I understand correctly, you have a main layout blade template that is later extended by the user view returned by the controller.
No additional code like you described is needed. Both user and layout templates are processed after controller action is executed and both have access to user session via session() helper and user object via Auth::user().
So the following sample code should work for you :
// SomeController
public function someAction() {
return return response()->view('user');
}
// main.blade.php
@if (Auth::check())
Show this text only to authenticated users
@endif
Value of session parameter is {{ session('parameter_name') }}
// user.blade.php
@extends('main')