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

image custom disk/folder #227

Closed
AurelDragut opened this issue Nov 7, 2016 · 7 comments
Closed

image custom disk/folder #227

AurelDragut opened this issue Nov 7, 2016 · 7 comments

Comments

@AurelDragut
Copy link

Hey fellas,

As some of you might know, i am working on some more complex page templates where i would like to add a few image fields on each template. I got their structure but i have a little problem when i start to implement. I wanna do something like a folder called uploads/pages/pagename/imagefile so i was thinking that maybe there is a way to optionally specify disk and folder when setting up the image field type so they can be read by the setImageAttribute function.

What do you think?

@OwenMelbz
Copy link
Contributor

@AurelDragut
Copy link
Author

Yes, but it would be nice if we add some parameters to that public function setImageAttribute($value) besides the value, so it won't be necessary to create a function for every image field

@OwenMelbz
Copy link
Contributor

setImageAttribute is core to laravel, it's nothing todo with backpack, it's just used as a callback when uploading an image.

@AurelDragut
Copy link
Author

Oh, right! I didn't recognize the way its name is constructed (it's a mutator). My bad!

@tabacitu
Copy link
Member

i don't think that's possible. SetImageAttribute() is in the model, $crud is in the controller, no connection between them.

I think a more appropriate solution to this would be a modified "upload_multiple" field. Something like "upload_multiple_images". That way you can have only one mutator. Sounds good?

@AurelDragut
Copy link
Author

Yeah, @tabacitu, it sounds good when i don't want to use the crop feature and it's ok. Anything else might be too much work to do and it doesn't seem necessary atm.

@sud5858
Copy link

sud5858 commented Sep 6, 2017

i am using
type field image for uploding when i delete the entry from database ....then the image is not remove from uploads folder

public function setImageAttribute($value)
{
$attribute_name = "image";
$disk = "uploads";
$destination_path = "drinks-category";

    // if the image was erased
    if ($value==null) {
        // delete the image from disk
        \Storage::disk($disk)->delete($this->image);
        dd($this->image);

        // set null in the database column
        $this->attributes[$attribute_name] = null;
    }

    // if a base64 was sent, store it in the db
    if (starts_with($value, 'data:image'))
    {
        // 0. Make the image
        $image = \Image::make($value);
        // 1. Generate a filename.
        $filename = md5($value.time()).'.jpg';
        // 2. Store the image on disk.
        \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
        // 3. Save the path to the database
        $this->attributes[$attribute_name] = $destination_path.'/'.$filename;
    }
}

This was referenced Apr 2, 2020
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

4 participants