1
I am creating an application where I have to validate the data sent to the database (obvious), however, I am responding to the following error:
Errorexception in Fileloader.php line 109:
Object of class Illuminate Routing Router could not be converted to string
So that you can understand better I will present 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');
...
}
Example of URL: /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 observed
I stopped the path presented in error, being it:
\path\vendor\laravel\framework\src\Illuminate\Translation\FileLoader.php
Linha: 109
And that’s the method:
protected function loadPath($path, $locale, $group)
{
if ($this->files->exists($full = "{$path}/{$locale}/{$group}.php")) {
return $this->files->getRequire($full);
}
return [];
}
If I put one 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 the problem must be in $locale
but I could not identify precisely which error, because I forced the same to $locale = "pt-BR"
and the error changes to:
Errorexception in Translator.php line 273:
Illegal offset type
I imagined that it could be error exactly in the translation files, however, I saw the same and it is also all right, however, for any doubt, follow the same on github.
Have you tried using this package here ? https://packagist.org/packages/mcamara/laravel-localization
– Richard Feliciano
Where does Intl enter? it is enabled?
– rray
Yes, Intl is enabled and if I remove the validation, everything works. The problem is when I try to validate the fields and returns an error.
– Ewerton Melo