Crud: How can i make image file on insert or update with rename and make thumb files?

Created on 5 Jul 2016  Â·  11Comments  Â·  Source: Laravel-Backpack/CRUD

hello!
How can i make image file on insert or update with rename and make thumb files?

question

All 11 comments

Hey!

any help int that ?
i dont know if i can resize and rename image on upload or not with this package?

thank you in advance

Hi!

Sure, you can use the "browse" field type and, on your model, use a mutator
to crop/resize/whatever you want to do with your image.

function setImageAttribute($value) {
// use Intervention image or whatever you want to process that image
$this->attribute['image'] = $value;
}

On Sunday, 10 July 2016, c1t1zen [email protected] wrote:

Hey!

any help int that ?
i dont know if i can resize and rename image on upload or not with this
package?

thank you in advance

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Laravel-Backpack/crud/issues/52#issuecomment-231582798,
or mute the thread
https://github.com/notifications/unsubscribe/AA_BGuhkh_geIcJvr0QJQAIxqhHEo09Xks5qUM-WgaJpZM4JFUMG
.

[image: photo]
_Cristian Tăbăcitu_
Managing Partner UPDIVISION
http://s.wisestamp.com/links?url=http%3A%2F%2Fupdivision.com&sn=Y3Jpc3RpdGFiYWNpdHVAZ21haWwuY29t
http://s.wisestamp.com/links?url=http%3A%2F%2Falternopedia.ro&sn=Y3Jpc3RpdGFiYWNpdHVAZ21haWwuY29tBoard
Member Ideo Ideis
http://s.wisestamp.com/links?url=http%3A%2F%2Fideoideis.ro&sn=Y3Jpc3RpdGFiYWNpdHVAZ21haWwuY29t
| mobile: +4 0752 233 319 | website: http://tabacitu.ro/
http://s.wisestamp.com/links?url=http%3A%2F%2Ftabacitu.ro&sn=Y3Jpc3RpdGFiYWNpdHVAZ21haWwuY29t
[image: Facebook]
http://s.wisestamp.com/links?url=https%3A%2F%2Fwww.facebook.com%2Ftabacitu&sn=Y3Jpc3RpdGFiYWNpdHVAZ21haWwuY29t
[image: LinkedIn]
http://s.wisestamp.com/links?url=http%3A%2F%2Fro.linkedin.com%2Fin%2Ftabacitu&sn=Y3Jpc3RpdGFiYWNpdHVAZ21haWwuY29t
[image: Google Plus]
http://s.wisestamp.com/links?url=http%3A%2F%2Fplus.google.com%2F111602517732305461201&sn=Y3Jpc3RpdGFiYWNpdHVAZ21haWwuY29t
Video conference: [image: Google Talk] cristitabacitu [image: Skype]
cristitabacitu

Thank you alot
i did make it in this link for other people so they can do it if they need

https://github.com/Laravel-Backpack/crud/issues/57

can i get last inserted id in modal in ?

function setImageAttribute($value) {
// use Intervention image or whatever you want to process that image
$this->attribute['image'] = $value;
}

thank you again

Sure, just get the current id using $this->id

yes i did put $this->id in method but did not work i got null

function setImageAttribute($value) {
// use Intervention image or whatever you want to process that image
$this->attribute['image'] = $this->id.'_'.$value;
}
when i checked table it does not print the id as id_$value

That's odd. I have quite a few mutators working this way.

1) Are you sure you have your image in your $fillable array, on your model? The CRUD will only save what's in the fillable array.

protected $fillable = ['name', 'image'];

2) Try looking at the Laravel documentation on Mutators, maybe you've missed something. Doing a dd($this->id); in your setImageAttribute() method should dump the correct ID.

it was
protected $fillable = ['slug', 'title', 'content', 'image', 'status', 'category_id', 'featured', 'date'];
i can save image name after rename it with no problem but when i try to add
id_imageName.jpg it just save as _imageName.jpg in the db table

Does $this->getKey() work, instead of $this->id?

@c1t1zen,

Did this work for you? Can I close the issue?

Cheers!

yes Close it thank you

Was this page helpful?
0 / 5 - 0 ratings