phplaravelhardcodehardcodedhard-coding

String Resource in laravel programming?


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.


Solution

  • 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);