0

Why I can't use PHP Collator class in my Laravel controller (Laravel 8)?

When I use $collator = new Collator('sl_SI'); in config or view file it works OK, but when I try using it in controller I get error:

Call to undefined function App\Http\Controllers\Myapp\Collator()

Any suggestions?

ADyson
  • 57,178
  • 14
  • 51
  • 63
Aleš
  • 79
  • 1
  • 9
  • Please provide a [mre] of the issue. But I'd guess maybe you forgot to use the namespace or something. Or perhaps the relevant script file isn't included in the right place. Hard to say without more context. See also [ask]. – ADyson Jun 09 '23 at 08:17

1 Answers1

1

I would guess you forgot to add the namespace

use Collator; 

at the top of your Controller.

If that isn't working, you should add some code examples.

Tpojka
  • 6,996
  • 2
  • 29
  • 39
Daan
  • 26
  • 3
  • Thanks alot, this was my problem. I wasn't sure how to include PHP native class :) – Aleš Jun 09 '23 at 08:30
  • When importing class, prefixed backslash is not needed. Prefixed backslash is needed when used in code without importing class at to top of the file which OP already experienced as an issue. – Tpojka Jun 09 '23 at 21:14