Laravel-Backpack / addons

A place for the Backpack community to talk about possible Backpack add-ons.
5 stars 2 forks source link

[Devtools][bug?] htmlspecialchars(): Argument #1 ($string) must be of type string, array given #44

Closed skpr-repo closed 1 year ago

skpr-repo commented 1 year ago

Bug report (maybe?)

What I did

When I visit admin/devtools/model I get this error:

htmlspecialchars(): Argument #1 ($string) must be of type string, array given {"view":{"view":"/home/vagrant/code/[...]/resources/views/vendor/backpack/devtools/livewire/modals/publish-modal.blade.php","data":[]},"exception":"[object] (Spatie\\LaravelIgnition\\Exceptions\\ViewException(code: 0): htmlspecialchars(): Argument #1 ($string) must be of type string, array given at /home/vagrant/code/[...]/vendor/laravel/framework/src/Illuminate/Support/helpers.php:123)
[stacktrace]
#0 /home/vagrant/code/[...]/vendor/laravel/framework/src/Illuminate/Support/helpers.php(123): htmlspecialchars()
#1 /home/vagrant/code/[...]/resources/views/vendor/backpack/devtools/livewire/modals/publish-modal.blade.php(19): e()

inside resources\views\vendor\backpack\devtools\livewire\modals\publish-modal.blade.php Logging the $key values inside the foreach loop at row 19, I found out that some keys have an $option = array instead of string. The two keys are "crud" and "pro".

Adding

@if(!is_array($option))
<option value="{{ $key }}" wire:key="file_option_{{ $loop->index }}">{{ $option }}</option>
@endif

solves the issue.

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.1.7 (cli) (built: Jun 10 2022 12:22:48) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.7, Copyright (c) Zend Technologies with Zend OPcache v8.1.7, Copyright (c), by Zend Technologies

LARAVEL VERSION:

v9.39.0@67e674709e1e7db14f304a871481f310822d68c5

BACKPACK VERSION:

5.4.7@6e1bb116de9f3091530cb9b11edcceb4d252daa8

Operating System and Server Setup

I encountered the problem above on my Windows 10 machine, Google Chrome latest and my web server is set up using Homestead. MySql 8. composer update to the latest versions. I have a license for backpack pro, devtools and editable-columns, latest version.

Thanks

skpr-repo commented 1 year ago

When I create and save a new Model (with bottom default checkboxes values) I get this error, but Model and Controller are created successfully:

array_filter(): Argument #1 ($array) must be of type array, null given {"exception":"[object] (TypeError(code: 0): array_filter(): Argument #1 ($array) must be of type array, null given at /home/vagrant/code/[...]/vendor/backpack/crud/src/app/Library/CrudPanel/Traits/SaveActions.php:52)
[stacktrace]
#0 /home/vagrant/code/[...]/vendor/backpack/crud/src/app/Library/CrudPanel/Traits/SaveActions.php(52): array_filter()
#1 /home/vagrant/code/[...]/vendor/backpack/crud/src/app/Library/CrudPanel/Traits/SaveActions.php(28): Backpack\\CRUD\\app\\Library\\CrudPanel\\CrudPanel->getSaveActionByOrder()
#2 /home/vagrant/code/[...]/vendor/backpack/crud/src/app/Library/CrudPanel/Traits/SaveActions.php(307): Backpack\\CRUD\\app\\Library\\CrudPanel\\CrudPanel->getFallBackSaveAction()
#3 /home/vagrant/code/[...]/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(338): Backpack\\CRUD\\app\\Library\\CrudPanel\\CrudPanel->setSaveAction()
#4 /home/vagrant/code/[...]/vendor/backpack/devtools/src/Http/Controllers/ModelCrudController.php(272): Illuminate\\Support\\Facades\\Facade::__callStatic()
#5 /home/vagrant/code/[...]/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Backpack\\DevTools\\Http\\Controllers\\ModelCrudController->store()
pxpm commented 1 year ago

Hello @skpr-repo About the first issue I think you may have an outdate file, as we currently don't have any loop on line 19:

image

The loop is on 53: image

The contents of $visibleOptions are splited in $project => $options and this are the contents:

image

As you can see $project = crud/pro and the options are key => value pairs that we get with foreach($options as $key => $option.

Please make sure you are requiring Devtools ^1.2 in your composer.json to get the latest version. You can do a composer why backpack/devtools to known the currently required version.

After you confirm you are in the latest version, please also verify if the last issue persist as I was not able to reproduce it either.

Cheers 🙏

skpr-repo commented 1 year ago

Thanks, I don't know why this file wasn't updated. Anyway now I have version 1.2 and it works. But I still have the other error when I create a new model array_filter(): Argument #1 ($array) must be of type array, null given

tabacitu commented 1 year ago

Merged, will be tagged later today! 🎉 Thanks guys!