public function __construct() { $this->middleware(function ($request, $next) { // get all shops $shops = Shop::all(); // if there are no shops force user to add one if (count($shops) == 0) { $request->session()->flash('warning', trans('shops.required')); return redirect('shops/create'); } // if session is not set or the shop doesn't exist reset the session for the shop if (!$request->session()->has('shop') || Shop::where('_id', '=', $request->session()->get('shop'))->count() == 0) { $shop = Shop::first(); $request->session()->put('shop', $shop->id); $request->session()->put('shop_url', $shop->url); } // if session is not set reset the session for the language if (!$request->session()->has('language')) { $request->session()->put('language', config('app.locale')); } // if limit is not set default pagination limit if (!$request->session()->has('limit')) { $request->session()->put('limit', 100); } view()->share('select_shops', $shops); view()->share('languages', Language::LANGUAGES); view()->share('language', $request->session()->get('language')); return $next($request); }); }
public function __construct(Route $route) { $this->middleware(function ($request, $next) { // if session is not set get it from .env SHOP_CODE if (!$request->session()->has('shop')) { $shop = Shop::where('code', config('app.shop_code'))->first(); $request->session()->put('shop', $shop->id); } // if limit is not set default pagination limit if (!$request->session()->has('limit')) { $request->session()->put('limit', 100); } // if session is not set reset the session for the language if (!$request->session()->has('language')) { $request->session()->put('language', config('app.locale')); } // if session is not set reset the session for the basket if (!$request->session()->has('basket')) { $request->session()->put('basket', ['subtotal' => 0, 'count' => 0, 'items' => []]); } // global list of categories $categories = Category::where('shop_id', $request->session()->get('shop'))->orderBy('order', 'asc')->get(); // share globals view()->share('language', $request->session()->get('language')); view()->share('categories', $categories); return $next($request); }); // add controller & action to the body class $currentAction = $route->getActionName(); list($controller, $method) = explode('@', $currentAction); $controller = preg_replace('/.*\\\\/', '', $controller); $action = preg_replace('/.*\\\\/', '', $method); view()->share('body_class', $controller . '-' . $action); }
/** * Re order shop list * * @return Void */ public function order() { foreach (Input::get('ids') as $shop) { Shop::where('id', '=', (int) $shop['id'])->update(['order' => (int) $shop['order']]); } }