Thursday, April 13, 2017

[Laravel5][Resolved] BadMethodCallException Method locate does not exist.

I used Lang::locate() to get current message but failed, it's the error message:
(1/1) BadMethodCallException
Method locate does not exist.
in Macroable.php (line 74)
at Translator->__call('locate', array())
in Facade.php (line 221)
at Facade::__callStatic('locate', array())
Example code:
use Lang;
class OrderService
{
    protected $lang;
  
    public function __construct() {
        $this->lang = Lang::locate();
    }
Since there is a bit strange and i almost can't find anyone with this strange case on internet,
using "Config::get('app.locale');" to replace Lang::locate(); works.

use Config;
 class OrderService
{
    protected $lang;
  
    public function __construct() {
        $this->lang = Config::get('app.locale');
    }
}

Reference

https://stackoverflow.com/questions/12706463/how-can-i-find-the-current-language-in-a-laravel-view

No comments :

Post a Comment