Przeglądaj źródła

Exception handler

jqh 6 lat temu
rodzic
commit
6cdbe34b8a

+ 2 - 15
config/admin.php

@@ -331,24 +331,11 @@ return [
 
     /*
     |--------------------------------------------------------------------------
-    | Show version at footer
+    | The exception handler class
     |--------------------------------------------------------------------------
     |
-    | Whether to display the version number of dcat-admin at the footer of
-    | each page
-    |
-    */
-    'show_version' => true,
-
-    /*
-    |--------------------------------------------------------------------------
-    | Show environment at footer
-    |--------------------------------------------------------------------------
-    |
-    | Whether to display the environment at the footer of each page
-    |
     */
-    'show_environment' => true,
+    'exception_handler' => \Dcat\Admin\Exception\Handler::class,
 
     /*
     |--------------------------------------------------------------------------

+ 3 - 17
src/Exception/Handler.php

@@ -14,7 +14,7 @@ class Handler
      *
      * @return string
      */
-    public static function renderException(\Throwable $exception)
+    public function renderException(\Throwable $exception)
     {
         if (config('app.debug')) {
             throw $exception;
@@ -33,26 +33,12 @@ class Handler
         return view('admin::partials.exception', compact('errors'))->render();
     }
 
-    /**
-     * Flash a error message to content.
-     *
-     * @param string $title
-     * @param string $message
-     *
-     * @return mixed
-     */
-    public static function error($title = '', $message = '')
-    {
-        $error = new MessageBag(compact('title', 'message'));
-
-        return session()->flash('error', $error);
-    }
-
     /**
      * @param \Throwable $e
+     *
      * @return mixed
      */
-    public static function handleDestroyException(\Throwable $e)
+    public function handleDestroyException(\Throwable $e)
     {
         $root = dirname(app_path());
 

+ 2 - 2
src/Form.php

@@ -489,7 +489,7 @@ class Form implements Renderable
                 'message' => trans('admin.delete_succeeded'),
             ];
         } catch (\Throwable $exception) {
-            $response = Handler::handleDestroyException($exception);
+            $response = app(config('admin.exception_handler'))->handleDestroyException($exception);
 
             $response = $response ?: [
                 'status'  => false,
@@ -1381,7 +1381,7 @@ class Form implements Renderable
 
             return $this->builder->render();
         } catch (\Throwable $e) {
-            return Handler::renderException($e);
+            return app(config('admin.exception_handler'))->renderException($e);
         }
     }
 

+ 1 - 1
src/Form/Field/Tags.php

@@ -47,7 +47,7 @@ class Tags extends Field
             $value = array_column($value, $this->visibleColumn, $this->key);
         }
 
-        return array_filter(Helper::array($value), 'strlen');
+        return Helper::array($value);
     }
 
     /**

+ 2 - 1
src/Grid.php

@@ -1164,11 +1164,12 @@ HTML;
         $this->handleExportRequest(true);
 
         try {
+            echo $a;
             $this->callComposing();
 
             $this->build();
         } catch (\Throwable $e) {
-            return Handler::renderException($e);
+            return app(config('admin.exception_handler'))->renderException($e);
         }
 
         return $this->doWrap();

+ 1 - 1
src/Widgets/AjaxRequestBuilder.php

@@ -34,7 +34,7 @@ trait AjaxRequestBuilder
 
     public function requestCurrent(array $query = [])
     {
-        $this->url = '?'.http_build_query($query);
+        $this->url = url(request()->getPathInfo()).'?'.http_build_query($query);
 
         return $this;
     }