83 lines
2.3 KiB
PHP
Executable File
83 lines
2.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Attachment extends Model
|
|
{
|
|
use CrudTrait;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| GLOBAL VARIABLES
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
protected $table = 'attachments';
|
|
// protected $primaryKey = 'id';
|
|
// public $timestamps = false;
|
|
// protected $guarded = ['id'];
|
|
protected $fillable = [
|
|
'name', 'size', 'type', 'file', 'document_id', 'application_id'
|
|
];
|
|
// protected $hidden = [];
|
|
// protected $dates = [];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| FUNCTIONS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| RELATIONS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public function application(){
|
|
return $this->belongsTo(Application::class, 'application_id');
|
|
}
|
|
|
|
public function document(){
|
|
return $this->belongsTo(Document::class, 'document_id');
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| SCOPES
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| ACCESSORS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| MUTATORS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public function setFileAttribute($value)
|
|
{
|
|
$attribute_name = 'file';
|
|
$disk = 'public';
|
|
$destination_path = 'uploads/attachments';
|
|
|
|
$this->uploadFileToDisk($value, $attribute_name, $disk, $destination_path);
|
|
|
|
// return $this->attributes[{$attribute_name}]; // uncomment if this is a translatable field
|
|
}
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
static::deleting(function($obj) {
|
|
\Storage::disk('public')->delete($obj->file);
|
|
});
|
|
}
|
|
}
|