/**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $visitor = new Visitor();
     $visitor->checkVisitor();
     $this->app->singleton('site_settings', function () {
         $settings = Setting::all();
         $keys = array();
         foreach ($settings as $setting) {
             $keys[$setting->key] = $setting->value;
         }
         return $keys;
     });
     View::share('site_settings', app('site_settings'));
     $this->app->singleton('site_menus', function () {
         $categories = Category::all();
         return $categories;
     });
     View::share('site_menus', app('site_menus'));
     $this->app->singleton('site_statistic', function () {
         $article = Article::whereStatus('published')->count();
         $member = Contributor::whereStatus('activated')->count();
         return ['article' => $article, 'member' => $member];
     });
     View::share('site_statistic', app('site_statistic'));
     Validator::extend('check_password', function ($attribute, $value, $parameter) {
         if (count($parameter) > 0 && $parameter[0] == 'admin') {
             return Hash::check($value, Auth::guard('admin')->user()->getAuthPassword());
         }
         return Hash::check($value, Auth::user()->getAuthPassword());
     });
     Blade::directive('datetime', function ($expression) {
         return "<?php echo with{$expression}->format('d/m/Y H:i'); ?>";
     });
     Blade::directive('simpledate', function ($expression) {
         return "<?php echo with{$expression}->format('d M Y'); ?>";
     });
     Blade::directive('fulldate', function ($expression) {
         return "<?php echo with{$expression}->format('d F Y'); ?>";
     });
     Blade::directive('datetime', function ($expression) {
         return "<?php echo with{$expression}->format('d F Y h:m A'); ?>";
     });
 }
 /**
  * Display a listing of the category.
  *
  * @param Request $request
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     $filter = $request->get('filter', 'merge');
     $sub = explode(':', $filter);
     if ($sub[0] == 'subcategory') {
         if (isset($sub[1]) && $sub[1] > 0) {
             $menu = Subcategory::whereCategoryId($sub[1])->get();
         } else {
             $menu = Subcategory::all();
         }
     } else {
         if ($filter == 'category') {
             $menu = Category::all();
         } else {
             $menu = Category::with('subcategories')->get();
         }
     }
     return ['request_id' => uniqid(), 'status' => 'success', 'timestamp' => Carbon::now(), 'categories' => $menu];
 }