Laravel Scout:仅在特定字段更改时更新

我正在尝试使用 php 删除文件夹中的图像,但我似乎收到此错误:注意:第 89 行 C:\xampp\htdocs\teadmised\upload.php 中的数组到字符串的转换


为什么我不能用数组值添加字符串值?


        $stmt = $pdo->query('SELECT image FROM posts WHERE post_id =' . $number . ' AND NOT image="noimage.png";');

        $allFileNames = $stmt->fetchAll();



        $countAllNames = count($allFileNames);



        for($i=0; $i < $countAllNames; $i++) {


            $path = "uploads/" . $allFileNames[$i];  // something is wrong in here

            if(!unlink($path)) {

                echo "You have an error!";

                exit();

            }

        }


慕标5832272
浏览 89回答 2
2回答

吃鸡游戏

该withoutSyncingToSearch 方法是您正在寻找的方法吗?这意味着在您当前使用此方法更新价格的任何地方进行换行。虽然您的问题中未提供此代码,但我假设以下内容:\App\Model::withoutSyncingToSearch ( function() use ($item, $newPrice) {&nbsp; &nbsp; $item->price = $newPrice;&nbsp; &nbsp; $item->save();});可以为你工作吗?

MMTTMM

将以下功能添加到您的模型中:public function searchIndexShouldBeUpdated(){&nbsp; &nbsp; if (empty(array_intersect_key( $this->getChanges(),$this->toSearchableArray() )))&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; return true;&nbsp; &nbsp; }}它将检查上次更新是否更改了可搜索数组中的任何属性,并且仅在进行了此类更新时才更新搜索索引。
打开App,查看更多内容
随时随地看视频慕课网APP