I'm creating an application where I have to validate the data sent to the bank (obvious), but I'm having the following error:
ErrorException in FileLoader.php line 109:
Object of class Illuminate \ Routing \ Router could not be converted to string
For you to understand better, I'll introduce my code:
routes / web.php
...
Route::group(['prefix' => 'dashboard/{locale}/'], function($locale) {
if (empty($locale)) {
$locale = 'pt-BR';
}
App::setLocale($locale);
...
Route::get('api/add', 'ApiController@addApi');
Route::post('api/add', 'ApiController@storeApi');
...
}
URL Example: /dashboard/pt-BR/api/add
app / Http / Controllers / ApiController.php
public function storeApi(Request $request)
{
$validator = Validator::make(
$request->all(),
$this->rules,
$this->messages
)->validate(); // Por padrão, em caso de erro, ele retornaria para o form com os erros.
$api = $this->apiRepository->model()->create($request->all());
// $this->locale = 'pt-BR' - É recuperado por um middleware...
if ($api) {
return redirect()->to(
'dashboard/' . $this->locale .
'/api/add-accounting/' . $api['id']
);
}
}
One thing I noticed
I accessed the path presented in the error, it being:
\path\vendor\laravel\framework\src\Illuminate\Translation\FileLoader.php
Linha: 109
And the method is this:
protected function loadPath($path, $locale, $group)
{
if ($this->files->exists($full = "{$path}/{$locale}/{$group}.php")) {
return $this->files->getRequire($full);
}
return [];
}
If I put a dd()
in each parameter, I have:
$path = 'path\resources\lang'
$locale = Router {#24 ▼
#events: Dispatcher {#5 ▶}
#container: Application {#3 ▶}
#routes: RouteCollection {#26 ▶}
#current: Route {#230 ▶}
#currentRequest: Request {#40 ▶}
#middleware: array:6 [▶]
#middlewareGroups: array:2 [▶]
+middlewarePriority: array:5 [▶]
#binders: array:1 [▶]
#patterns: []
#groupStack: []
}
$group = 'validation'
I particularly think that the problem should be in $locale
but I could not accurately identify the error, because I forced it to $locale = "pt-BR"
and the error changes to:
ErrorException in Translator.php line 273:
Illegal offset type
I imagined that it might be an error in the translation files, but I have validated it and everything is fine, but for any doubt, follow the same in github .