Как исправить ошибки Call to undefined function и Undefined index: disabled?

помогите разобрать уже много что перепробовал ни могу исправить

Call to undefined function App\Http\Controllers\array_prepend() {"userId":14,"exception":"[object] (Error(code: 0): Call to undefined function App\\Http\\Controllers\\array_prepend() at /var/www/html/app/Http/Controllers/AdminController.php:29)
public static function log($type, $data, $user_id = null) {
        if($user_id == null && Auth::guest()) return;

        $json = json_decode(file_get_contents(storage_path().'/actions.json'), true);

        $json = array_prepend($json, array(
            "id" => $user_id == null ? Auth::user()->id : $user_id,
            "type" => $type,
            "time" => time(),
            "data" => $data
        ));
        file_put_contents(storage_path().'/actions.json', json_encode($json));
    }

вторая ошибка

Undefined index: disabled {"userId":1,"exception":"[object] (ErrorException(code: 0):

вот код где ошибка
public static function toggleDisabled($pull) {
        $json = json_decode(file_get_contents(storage_path().'/disabled.json'), true);
        if(in_array($pull, $json['disabled'])) array_push($json['disabled'], $pull);
        else unset($json['disabled'][array_search($pull, $json['disabled'])]);
        file_put_contents(storage_path().'/disabled.json', json_encode($json));
        return true;
    }
  • Вопрос задан
  • 1152 просмотра
Решения вопроса 3
@inFureal
1. Очевидно нет такой функции, забыл подключить файл или функция называется по другому
2. Походу в $json не всегда есть ключ disabled
public static function toggleDisabled(array $pull) {
        $path = storage_path('disabled.json');
        $json = json_decode(file_get_contents($path), true);

        if (!isset($json['disabled']))
                return false;

        if(in_array($pull, $json['disabled'])) 
                array_push($json['disabled'], $pull);
        else 
                unset($json['disabled'][array_search($pull, $json['disabled'])]);

        file_put_contents($path, json_encode($json));
        return true;
    }
Ответ написан
Rsa97
@Rsa97
Для правильного вопроса надо знать половину ответа
1. Функция array_prepend в стандартном наборе PHP отсутствует.
2. Либо неверный формат JSON в файле disabled.json, либо в JSON нет элемента с индексом 'disabled'.
Ответ написан
xmoonlight
@xmoonlight
https://sitecoder.blogspot.com
У Вас отсутствует библиотека сторонних функций для работы с массивами (array_*).
Найдите недостающий файл/код и подключите.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы