Maybe this work:
json_decode(file_get_contents('/path/to/your/file.json'));
could you help me with the following question. I need to get the content of a translation file as an array regardless of whether it is a PHP file or a JSON file.
Suppose I have the following structure in my project:
laravel_project/resources/lang/
├── en
├── es
├── file1.php
├── file2.json
...
and I have the following method:
public function example()
{
dd(__('file1', [], '/'));
}
I get the following result:
array:2 [
"failed" => "These credentials do not match our records."
"throttle" => "Too many login attempts. Please try again in :seconds seconds."
]
Which is great since it is the content of the file1.php file, but I wonder how I can get the content of the file2.json file in the same way, because when I do the following:
public function example()
{
dd(__('file2', [], '/'));
}
I get the following result:
"file2"
The content of the file2.json file is the following:
{
"A": "My string A",
"B": "My string B"
}
I mean, it is not returning the content of the file file2.json. Is there an elegant way to achieve what I am trying to do? Basically what I am trying to do is return the content of a translation file regardless of whether it is a PHP file or a JSON file. Thank you very much in advance.
Please or to participate in this conversation.