Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to set image_base for absolute image URLs #25

Closed
bellwood opened this issue Aug 15, 2018 · 2 comments
Closed

Option to set image_base for absolute image URLs #25

bellwood opened this issue Aug 15, 2018 · 2 comments

Comments

@bellwood
Copy link

I am using laravel mix for my images which generates a relative path to the image via mix().

I'm finding myself repetitively prepending env('APP_URL') in my meta::set('image','...') so my images are absolutely pathed.

Could we have a option in config.php for 'image_base' => env('APP_URL') to permit this functionality?

Thank you =)

@eusonlito
Copy link
Owner

You can extend package Meta class and add the config('app.url') for each image (remember, you should never use env helper into your source code, only on config files).

# app/Services/Html/Meta.php

<?php
namespace App\Services\Html;

class Meta extends \Meta
{
    /**
     * @param  string $value
     *
     * @return string
     */
    protected function setImage($value)
    {
        if (count($this->metas['image']) >= $this->config['image_limit']) {
            return '';
        }

        $this->metas['image'][] = config('app.url').$value;

        return $value;
    }
}
# config/app.php

'aliases' => [
   ...

   'Meta' => App\Services\Html\Meta::class,

   ...
];

@bellwood
Copy link
Author

Thank you very much...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants