[Laravel] Config & Language files in subfolder(s)

In my first post I would like to show you how to get access for strings in subfolder's files for config and language in Laravel framework.

Why do that?

I'm doing bigger website with many strings for translation / config and I just don't wanna to get lost.

One of possibility is to write every single string to same file. Another one is to have many files in one folder but soon or later it's easy to get lost anyway.

So I decided to use subfolder(s) in config / language folder.

Like this:

config / lang
├── subfolder
│   └── file
├── subfolder_2
│   └── file_2

How to do it

Accessing translation string or config string from subfolder is easy. However there is one difference.

Language files

In this case we just need to write subfolder's name and "/" (slash).


Blade:
@lang('subfolder_name/file.string')

PHP:
__('subfolder_name/file.string')

Config files

Accessing config string is a little bit difference than accessing translation string.

This time we won't use "/" (slash) but just "." (dot).


Blade:
{{ Config::get('subfolder_name.file.string') }}

PHP:
Config::get('subfolder_name.file.string')

That's it and I'm hoping this post will helps someone.