is there any way that instead of hard coding strings in the blade you use something like a string resource(or string table) so if you change a string every blade will be changed . For example instead of hoard coding "product" in the blade I use a variable called "string1" so if one day I change string1 value to "service" every blade will be affected and fine.
Asked
Active
Viewed 1,319 times
0
-
use a lang/localization string, or create a file inside the config folder end fetch it with Config::get('file.array_item'); – Calin Blaga Jul 18 '16 at 12:32
4 Answers
1
I am new to laravel but here is a idea I have.
create myString.php which contains your variables
example:
<?php
$string1 = "products";
?>
in your files
<?php
inlude_once("myString.php");
{{ $string1 }}
?>
I hope this helped you to come up with a better solution.
good luck.

Sahith Vibudhi
- 4,935
- 2
- 32
- 34
1
maybe use localization with language files, so you can use
{{ trans('string1') }}
in a blade view. more info: https://laravel.com/docs/5.0/localization
and these 2 functions
trans
Translate a given language line. Alias of Lang::get.
$value = trans('validation.required'):
trans_choice
Translate a given language line with inflection. Alias of Lang::choice.
$value = trans_choice('foo.bar', $count);

Alex Meyer
- 235
- 1
- 7
0
As of Laravel 5.4, you can use the double underscore:
{{ __('Register') }}
What is nice about this is that you don’t need to do anything else for it to output (in this case) “Register”.
You can change what value is displayed either in the appropriate messages.php file or by creating a json file, as described in the docs.

Laurel
- 5,965
- 14
- 31
- 57