SolvedCRUD ReflectionException Class translator does not exist

Bug report

What I did:

A clean install following the official guide: https://laravel-backpack.readme.io/docs/install-on-laravel-55

What I expected to happen:

Have a clean install of Backpack Base and CRUD.

What happened:

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')]],.

What I've already tried to fix it:

  • composer update to make sure everything is up to date;
  • replace the entire trans function with All which fixed the issue for me.;

Backpack, Laravel, PHP, DB version:

  • Backpack latest version (clean install);
  • Laravel latest (5.6.5, clean install);
  • PHP 7.2.1 build 4 Jan 2018;
  • DB 10.1.30-MariaDB;
16 Answers

✔️Accepted Answer

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: #1270

Other Answers:

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 hello@tabacitu.ro 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!

More Issues: