help desk create view

This commit is contained in:
merdan 2020-05-05 12:45:44 +05:00
parent 44a6bbb790
commit e9052e283e
1 changed files with 7 additions and 22 deletions

View File

@ -60,34 +60,19 @@ class HelpTicket extends Model
| MUTATORS
|--------------------------------------------------------------------------
*/
public function setAttachmentAttribute($value){
public function setAttachmentAttribute($file){
$attribute_name = "attachment";
$disk = config('filesystems.default'); // or use your own disk, defined in config/filesystems.php
$destination_path = "help"; // path relative to the disk above
// if the image was erased
if ($value==null) {
// delete the image from disk
\Storage::disk($disk)->delete($this->{$attribute_name});
// set null in the database column
$this->attributes[$attribute_name] = null;
if($file){
$filename = md5($file.time()) . '.' . strtolower($file->getClientOriginalExtension());
// 2. Move the new file to the correct path
$file_path = $file->storeAs($destination_path, $filename, $disk);
$this->attributes[$attribute_name] = $file_path;
}
// if a base64 was sent, store it in the db
if (starts_with($value, 'data:image'))
{
// 0. Make the image
$image = \Image::make($value)->encode('jpg', 90);
// 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 public path to the database
// but first, remove "public/" from the path, since we're pointing to it from the root folder
// that way, what gets saved in the database is the user-accesible URL
$public_destination_path = Str::replaceFirst('public/', '', $destination_path);
$this->attributes[$attribute_name] = $public_destination_path.'/'.$filename;
}
}
/**
* Boot all of the bootable traits on the model.