Attendize/app/Models/HelpTicketComment.php

95 lines
2.8 KiB
PHP
Raw Normal View History

2020-04-29 11:48:01 +00:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Backpack\CRUD\CrudTrait;
2020-05-01 10:54:03 +00:00
use Illuminate\Support\Str;
2020-04-29 11:48:01 +00:00
class HelpTicketComment extends Model
{
use CrudTrait;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $table = 'help_ticket_comments';
// protected $primaryKey = 'id';
2020-04-29 12:55:49 +00:00
public $timestamps = true;
2020-04-29 11:48:01 +00:00
// protected $guarded = ['id'];
2020-04-29 12:55:49 +00:00
protected $fillable = ['text','attachment','parent_id','user_id','name','help_ticket_id'];
2020-04-29 11:48:01 +00:00
// protected $hidden = [];
// protected $dates = [];
/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/
2020-04-29 12:55:49 +00:00
public function ticket(){
return $this->belongsTo(HelpTicket::class);
}
2020-05-06 14:28:06 +00:00
public function user(){
return $this->belongsTo(User::class);
}
2020-04-29 11:48:01 +00:00
/*
|--------------------------------------------------------------------------
| SCOPES
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| ACCESORS
|--------------------------------------------------------------------------
*/
2020-05-06 14:28:06 +00:00
public function getOwnerAttribute(){
return $this->user->full_name ?? $this->name;
}
2020-04-29 11:48:01 +00:00
/*
|--------------------------------------------------------------------------
| MUTATORS
|--------------------------------------------------------------------------
*/
2020-05-01 10:54:03 +00:00
//todo use trait for image upload
2020-05-08 10:54:00 +00:00
public function setAttachmentAttribute($file){
2020-05-01 10:54:03 +00:00
$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
2020-05-08 10:54:00 +00:00
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);
2020-05-01 10:54:03 +00:00
2020-05-08 10:54:00 +00:00
$this->attributes[$attribute_name] = $file_path;
2020-05-01 10:54:03 +00:00
}
}
/**
* Boot all of the bootable traits on the model.
*/
public static function boot()
{
parent::boot();
static::deleting(function($obj) {
$disk = config('filesystems.default');
\Storage::disk($disk)->delete($obj->seats_image);
});
}
2020-04-29 11:48:01 +00:00
}