Closed agustinprod closed 5 years ago
I second this. For me, the login form did not display, because the __('Login')
translation used in the vendor/laravel/nova/resources/views/auth/login.blade.php
template pulled up the array from my project's resources/lang/en/login.php
file, causing a "htmlspecialchars() expects parameter 1 to be string, array given"
exception.
Same issue here with {{ __('Dashboard') }}
.
In my production there was no error. On my Windows dev enviroment I got a blank nova screen and the following error in the logs:
[2019-02-16 20:39:59] local.ERROR: Method Illuminate\View\View::__toString() must not throw an exception, caught ErrorException: htmlspecialchars() expects parameter 1 to be string, array given (View: D:\MAMP\htdocs\XXXX.localhost\vendor\laravel\nova\resources\views\dashboard\navigation.blade.php) {"userId":1,"email":"XXXXXX","exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1): Method Illuminate\\View\\View::__toString() must not throw an exception, caught ErrorException: htmlspecialchars() expects parameter 1 to be string, array given (View: D:\\MAMP\\htdocs\\XXX.localhost\\vendor\\laravel\
ova\
esources\\views\\dashboard\
avigation.blade.php) at D:\\MAMP\\htdocs\\XXXX.localhost\\storage\\framework\\views\\df52af84a287f442b4ed31816c5013ce005ad98e.php:0)
[stacktrace]
#0 {main}
"}
My problem was in nova/resources/views/dashboard/navigation.blade.php
: <span class="text-white sidebar-label">{{ __('Dashboard') }}</span>
. Windows is not case sensitive. Linux is case sensitive and dashboard
is not Dashboard
. So there was no error on the production server.
There will likely be no plans to implement this feature.
I second this, got exactly the same problem. If anyone has a working solution would deeply appreciate
htmlspecialchars() expects parameter 1 to be string, array given (View: /home/vagrant/code/vendor/laravel/nova/resources/views/dashboard/navigation.blade.php) (View: /home/vagrant/code/vendor/laravel/nova/resources/views/dashboard/navigation.blade.php) (View: /home/vagrant/code/vendor/laravel/nova/resources/views/dashboard/navigation.blade.php)
caused by <span class="text-white sidebar-label">{{ __('Dashboard') }}</span>
The easiest way it's to change your app dashboard. translations to something else, like panel.
I think this is something that should be addressed, maybe in the next major release (? It's a pain to have to change localizations through all my app code just because Nova will try to load them from the global scope.
In the meantime, I override the Resource's label()
method:
/**
* Get the displayable label of the resource.
*
* We override this default Nova method because it'll try to
* load a localization from the "global" scope and it'll
* fail when there's a localization file with the same
* name as the value being localized.
* For example, this happens when Nova tries to localize the word
* "coupons" because we have both a Coupons Resource and a
* coupons.php localization file.
*
* Related:
* - https://github.com/laravel/nova-issues/issues/475
* - https://github.com/laravel/nova-issues/issues/1084
*
* @return string
*/
public static function label()
{
return Str::plural(Str::title(Str::snake(class_basename(get_called_class()), ' ')));
}
I used to have the same issue with {{ __('Dashboard') }}
last year, but I don't remember if I patched it or it got "fixed" in Nova. It's not giving any problem right now.
Same issue here when updating Nova recently. We have a resource called Documents and a translation file calles documents, so an array is passed into htmlspecialchars() in the e() method.
Same issue here when updating Nova recently. We have a resource called Documents and a translation file calles documents, so an array is passed into htmlspecialchars() in the e() method.
@metrixinfo how did you solve this? I probably have the same issue while I have a "documents" resource too
any solution for this?
I just renamed my translation files like: "order_strings" instead of just "order".
On Mon, Nov 9, 2020 at 10:15 AM LFTroya notifications@github.com wrote:
any solution for this?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/laravel/nova-issues/issues/475#issuecomment-724076375, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKO43AAKXU7SLKF2GZR45FDSPABR3ANCNFSM4FTZ6CNA .
@crynobone In my case I think it is using the translations of my app. I can't see which translations is giving me troubles.
I am still debugging, for the time being, I am using a local installation and changed the translation function
The translations for Nova should be namespaced. We have a key for several translations in the dashboard namespace, like:
dashboard.php
<?php return [ 'hi' => 'Hello', 'other' => 'other', ];
When nova tries to load, on the 'dashboard' key, the translation method returns an array instead the nova translation and throws an error when triying to print the array.