1

Experimenting with the creation of webstore on laravel 5.7. I am trying to implement the functionality of points of sale - individual stores, regions, countries, etc., which have their own individual products and prices.

Switch in header. When you visit the site it automatically set to the default value (then maybe it will be determined by location).

The problem. I can not decide how can I do it. User enters the site and ... so what? Where should the logic be described? View (header) - common to all pages. There I need to show the selected point of sale. So, I need to store it somewhere. And the code should work immediately when you open the site. This is something global with access to the cache. What is the best way to do this and how?

Teretto
  • 635
  • 2
  • 10
  • 22
  • you can do the check in the function of the controller just after the route redirect to the controller function, it should be executed there b4 u even load the view, to determine which you wanna display i guess. – Mr Mohamed Feb 21 '19 at 21:49
  • @MrMohamed what controllet? This view is global - it for all pages. So there are no separated route and controller – Teretto Feb 22 '19 at 08:10

1 Answers1

0

in this way you have to do it 1 of 4 ways which mentioned here, the i prefer is doing it through middleware, like this:-

Route::group(['middleware' => 'SomeMiddleware'], function(){
  // routes
});



class SomeMiddleware {
  public function handle($request)
  {
    \View::share('user', auth()->user());
  }
}

which you can find all the 4 here

Mr Mohamed
  • 454
  • 5
  • 12