I don't understand if your question is about the internationalization or about the way to display data tables without knowing which table is shown.
many tables, each needs to display different columns
I have a page that has a list of links to data tables. Each table shows different dataset with different column names. So the columns and column headers are different for each table. I am trying to make Laravel display all these tables using the same Blade file.
I was thinking about using Localization: https://laravel.com/docs/9.x/localization
For example, for the next table:
id | first_name | last_name | date_of_birth
I will do something like:
// lang/en_US.json
{
"first_name": "first name",
"last_name": "last name",
"date_of_birth": "date of birth",
}
Then replace the column names in Blade: (fetching the necessary columns from the Controller)
// for each column . .
<th> {{ __($column_name) }} </th>
// and so on
In this example it may look odd because I used English, but the actual app needs more languages other than English.
Is this a good solution or I should use something else?
*The only thing I'm not sure about is that this is not the actual purpose of localization - it's supposed to translate from one language to another, not from some values to english (and then to other languages)
@Ligonsker These are two different problems.
If you need to translate the columns names, you can use either a JSON file or a PHP language file as mentioned in the Laravel documentation.
For your second question about the columns names, you can retrieve the columns names using this method, for example for the Post model.
$postColumns = Schema::getColumnListing('posts');
Please or to participate in this conversation.