1

I have an image stored in public/images/image.jpg

I am using this image in several files. However, for the sake of convenience and saving time I would like to store that reference link as a variable. So instead of using <img src="/images/image.jpg"> it would be <img src="variable_name">. This would also allow me to edit the path that the variable is set to, without having to do it each time I use the image.

Thanks,

2
  • 1
    do you have PHP skills? this can be accomplished from several ways on the server-side... have you tried anyone? Maybe a constant? DB? Commented Sep 16, 2016 at 7:20
  • which version of laravel are you using? Commented Sep 16, 2016 at 7:25

1 Answer 1

1

Create a new file in the app/config directory. Let's call it constants.php. In there you have to return an array of config values.

return [
    'images' => [
        'myfixedImg1' => 'www.domain.es/public/images/img/img1.jpg',
        'myfixedImg2' => 'www.domain.es/public/images/img/img2.jpg'
    ]
];

And you can access all of them like this: Config::get('constants.images');

or a concrete one like: Config::get('constants.langs.en');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.