jqh 5 år sedan
förälder
incheckning
a88fed3e36
3 ändrade filer med 29 tillägg och 4 borttagningar
  1. 20 1
      src/Form.php
  2. 1 1
      src/Form/Condition.php
  3. 8 2
      src/Support/helpers.php

+ 20 - 1
src/Form.php

@@ -1107,7 +1107,26 @@ class Form implements Renderable
     }
 
     /**
-     * @param $condition
+     * @example
+     *     $form->if(true)->next(function (Form $form) {
+     *          $form->text('name');
+     *     });
+     *
+     *     $form->if(function (Form $form) {
+     *         return $form->model()->id > 5;
+     *     })->next(function (Form $form) {
+     *         $form->text('name');
+     *     });
+     *
+     *     $form->if(true)->then(function (Form $form) {
+     *         $form->text('name');
+     *     });
+     *
+     *     $form->if(true)->creating(function (Form $form) {});
+     *
+     *     $form->if(true)->removeField('name');
+     *
+     * @param bool|\Closure $condition
      *
      * @return Condition|$this
      */

+ 1 - 1
src/Form/Condition.php

@@ -45,7 +45,7 @@ class Condition
         }
 
         if ($next) {
-            $this->call($next);
+            $this->next($next);
         }
 
         foreach ($this->next as $callback) {

+ 8 - 2
src/Support/helpers.php

@@ -153,10 +153,16 @@ if (!function_exists('admin_trans')) {
      */
     function admin_trans($key, $replace = [], $locale = null)
     {
+        static $method = null;
+
+        if ($method === null) {
+            $method = version_compare(app()->version(), '6.0', '>=') ? 'get' : 'trans';
+        }
+
         $translator = app('translator');
 
         if ($translator->has($key)) {
-            return $translator->get($key, $replace, $locale);
+            return $translator->$method($key, $replace, $locale);
         }
         if (
             strpos($key, 'global.') !== 0
@@ -170,7 +176,7 @@ if (!function_exists('admin_trans')) {
                 return end($arr);
             }
 
-            return $translator->get($key, $replace, $locale);
+            return $translator->$method($key, $replace, $locale);
         }
 
         return last(explode('.', $key));