A clean install following the official guide: https://laravel-backpack.readme.io/docs/install-on-laravel-55
Have a clean install of Backpack Base and CRUD.
When finishing the CRUD package setup following the steps in the guide I got the following error when going to any page in my application: ReflectionException Class translator does not exist and according to the debug info on the screen it occurred in file C:\xampp\htdocs\apps\laravel\hotel\config\backpack\crud.php at line 42 which is 'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, trans('backpack::crud.all')]],.
composer update to make sure everything is up to date; All which fixed the issue for me.; I can confirm the problem:
It seems this has to do with calling trans() in config files which is apparently not possible in laravel 5.6 (but must have been in previous versions)
As a workaround, you can navigate to config/backpack/crud.php and update this line
'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, trans('backpack::crud.all')]],
to read:
'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'All ']],
Added a pull request with a more translation friendly fix: https://github.com/Laravel-Backpack/CRUD/pull/1270
I was able to reproduce this even though i was not on Laravel 5.6
Backpack, Laravel, PHP, DB version:
Edit:
The suggested quick fix helped btw
Can confirm, using Laravel 5.6.5 and backpack crud 3.3.11
Going through the installation steps for the first time and ran into the same issue.
I confirm it, the suggested fix, it works. With Laravel 5.6 the problem is about the helper trans() in the file /config/backpack/crud.php
Temporary I edit the line 42 I replace this line:
'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, trans('backpack::crud.all')]],
with this one:
'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
Thank you for the suggestion.
I can reproduce the issue with Laravel 5.5.35
Related SO https://stackoverflow.com/questions/45506239/reflectionexception-class-translator-does-not-exists
You cannot use translator in config files
I confirm it, in install step
after run php artisan vendor:publish --provider="Backpack\CRUD\CrudServiceProvider" --tag="elfinder"
php version:PHP 7.0.26
laravel version:5.5
crud version:3.3
I can confirm it.
After running php artisan vendor:publish --provider="Backpack\CRUD\CrudServiceProvider" --tag="public" it throws
In Container.php line 752:
Class translator does not exist
I can also confirm that the fix suggested fixes the problem.
PHP 7.0.23 (cli) (built: Aug 29 2017 06:17:16)
Laravel Framework 5.5.37 (clean install, going through installation steps)
If we remove the trans() function we can not further translate anything, it is a bad idea.
Why not something like this in the Read::getPageLengthMenu() method (written on the fly, not tested)
public function getPageLengthMenu()
{
if ($this->page_length_menu) {
$page_length_menu = $this->page_length_menu;
} else {
// otherwise return default value
$page_length_menu = config('backpack.crud.page_length_menu');
}
if (count($page_length_menu) === 2) {
foreach ($page_length_menu[1] as $key => $val) {
$page_length_menu[1][$key] = trans($val);
}
}
return $page_length_menu;
}
@alexiswbr the fix is not removing the trans function, it simply removes one call to that function from the config file because the function is not available for use at the point at which the config files are loaded.
Yes I understood, but in this case the "All" will not be translated in the view :(
So we remove it from the config file (we don't have the choise anyway), but we have to handle the translations!
And the only possible way to do so, I think, is when using the getPageLengthMenu method
So we make a loop on the potentials translatables strings and use the trans function here
@alexiswbr Ah gotcha, that's a fair point. Ok, ill work that into my PR later today and resubmit 馃憤
@alexiswbr updated https://github.com/Laravel-Backpack/CRUD/pull/1270 to include your auto translation, good call
I've just merged @DelightedD0D 's PR, which helps us avoid this. After a composer update just specify the trans() string without the trans method, and it will work. So:
- 'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, trans('backpack::crud.all')]],
+ 'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'backpack::crud.all']],
That being said... I messed up... I'm so _SO_ sorry for introducing this bug, and for not seeing this HUGE issue sooner. I have no excuses - I did not expect for Laravel to not like trans() inside the app's config, since it does like it in the package's config. So my tests didn't show this error. And for the past 2 weeks I've been laser-focused on Backpack/Base issues and completely ignored Backpack/CRUD. I've been able to make spectacular progress for Base, but because of that, I did not notice this issue.
Again - I am so SO sorry for noticing this issue sooner. In the future, if any of you catches a huge bug like this, please also send an email at [email protected] with URGENT or something in the subject - I should have dealt with this in a matter of minutes, not days.
Thank you so much @cristianuibar for reporting this, and @DelightedD0D for providing the excellent solution and PR. Very good teamwork here, the only weak link was me, unfortunately...
Cheers!
Most helpful comment
It seems this has to do with calling
trans()in config files which is apparently not possible in laravel 5.6 (but must have been in previous versions)As a workaround, you can navigate to
config/backpack/crud.phpand update this line'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, trans('backpack::crud.all')]],to read:
'page_length_menu' => [[10, 25, 50, 100, -1], [10, 25, 50, 100, 'All ']],Added a pull request with a more translation friendly fix: https://github.com/Laravel-Backpack/CRUD/pull/1270