0

I have to access to the session and get some values and share it with all my views I have used following code on my AppServiceProvider.php, but it returns null when I read my session, Following code I have tried

$errors = json_encode(session()->get('errors'));
View::share('validation_errors', $errors);

Without sharing if I call the same function and assigned it through controller before view been called it works without any problem.

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
nuz123
  • 11
  • 1
  • 5
  • 1
    Are you calling it after the session is created? – Iftikhar uddin Jan 21 '19 at 08:43
  • yea session created in previous controller – nuz123 Jan 21 '19 at 08:44
  • 2
    One thing to know the errors of validation is automatically shared with all vies by Laravel for you :) – Maraboc Jan 21 '19 at 08:44
  • 1
    @nuz123 Maraboc is right validation messaged are already shared in all views so please explain what are you trying to achive here. Ref @ https://laravel.com/docs/5.7/validation#quick-displaying-the-validation-errors – Iftikhar uddin Jan 21 '19 at 08:47
  • @Iftikharuddin after validation i redirect to another page in that case errors not came to front end therefore i used session to store the errors and retrieve from front end however it work if i set a variable and retrieve session and passed to the view. – nuz123 Jan 21 '19 at 09:52

0 Answers0