]> _ Git - cubist_cms-back.git/commitdiff
wip #5399
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Aug 2022 16:25:46 +0000 (18:25 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 19 Aug 2022 16:25:46 +0000 (18:25 +0200)
composer.json
src/app/Magic/Fields/Model.php
src/app/Magic/Fields/SelectFromModel.php

index 7571a7837d91d8db3919704714a8b57df1aeab79..d87d1940f00237efd39c026101601d99433e743e 100644 (file)
@@ -53,8 +53,7 @@
         "laravel/framework": "^v8.83",
         "laravel-lang/lang": "^10.1",
         "laravel-lang/publisher": "^10.3",
-        "spatie/laravel-permission": "^4.4|^5.5",
-        "opis/closure": "^3.6"
+        "spatie/laravel-permission": "^4.4|^5.5"
     },
     "require-dev": {
         "filp/whoops": "^2.14",
index d801b7d70bc21168e2c6ea6f30898e086aa026a8..205757f5cc6ab2a6ec7b12105b61bb1f2196235e 100644 (file)
@@ -5,6 +5,8 @@ namespace Cubist\Backpack\Magic\Fields;
 
 
 use Illuminate\Database\Query\Builder;
+use Laravel\SerializableClosure\Exceptions\PhpVersionNotSupportedException;
+use Laravel\SerializableClosure\SerializableClosure;
 
 class Model extends Field
 {
@@ -29,6 +31,9 @@ class Model extends Field
         $this->pluck($this->getAttribute('attribute'), true, $force);
     }
 
+    /**
+     * @throws PhpVersionNotSupportedException
+     */
     public function pluck($attr, $onlyGlobal = false, $force = false)
     {
         $bui = backpack_user() === null ? '' : backpack_user()->id;
@@ -43,7 +48,7 @@ class Model extends Field
         $tag = 'model_' . $modelClass;
         if ($force || !isset(static::$_options[$globalCacheKey])) {
             start_measure($globalCacheKey, 'Get options for model ' . $modelClass . ' / ' . $attr);
-            $closure = function () use ($modelClass, $attr, $modelScope) {
+            $closure = new SerializableClosure(function () use ($modelClass, $attr, $modelScope) {
                 set_time_limit(0);
                 /** @var \Illuminate\Database\Eloquent\Model $inst */
                 $inst = new $modelClass();
@@ -53,7 +58,7 @@ class Model extends Field
                     $q = $q->$modelScope();
                 }
                 return $q->where('created_ok', 1)->get()->pluck($attr, $inst->getKeyName())->toArray();
-            };
+            });
             $ttl = 86400;
             $cache = cache()->tags([$tag]);
             if ($force) {
index 34909ba942b7b96a4a86ac64e1a9636bb7dc94f0..47fad04247ebbf56565413ba224c9acd83fea159 100644 (file)
@@ -5,6 +5,7 @@ namespace Cubist\Backpack\Magic\Fields;
 
 
 use Cubist\Backpack\CubistBackpackServiceProvider;
+use Laravel\SerializableClosure\SerializableClosure;
 
 class SelectFromModel extends Model
 {
@@ -31,7 +32,7 @@ class SelectFromModel extends Model
                 'ajax' => $this->_ajax,
                 'order' => $this->_order,
                 'allows_null' => $this->_allows_null,
-                'searchLogic' => function ($query, $column, $searchTerm) use ($field) {
+                'searchLogic' => new SerializableClosure(function ($query, $column, $searchTerm) use ($field) {
                     $pluckAttr = $field->getAttribute('column_attribute', $field->getAttribute('attribute'));
                     $list = $field->pluck($pluckAttr);
                     $findIds = [];
@@ -44,7 +45,7 @@ class SelectFromModel extends Model
                         }
                     }
                     $query->orWhereIn($field->getName(), $findIds);
-                },
+                }),
             ]
         );
     }