oc-social-plugin/models/Attachment.php

83 lines
1.8 KiB
PHP

<?php namespace Zoomyboy\Social\Models;
use Event;
use Media\Classes\MediaLibrary;
use Model;
/**
* Attachment Model
*/
class Attachment extends Model
{
use \October\Rain\Database\Traits\Validation;
/**
* @var string The database table used by the model.
*/
public $table = 'zoomyboy_social_attachments';
/**
* @var array Guarded fields
*/
protected $guarded = ['*'];
/**
* @var array Fillable fields
*/
protected $fillable = [ 'remote_id', 'post_id', 'href', 'type' ];
/**
* @var array Validation rules for attributes
*/
public $rules = [];
/**
* @var array Attributes to be cast to native types
*/
protected $casts = [];
/**
* @var array Attributes to be cast to JSON
*/
protected $jsonable = [];
/**
* @var array Attributes to be appended to the API representation of the model (ex. toArray())
*/
protected $appends = [];
/**
* @var array Attributes to be removed from the API representation of the model (ex. toArray())
*/
protected $hidden = [];
/**
* @var array Attributes to be cast to Argon (Carbon) instances
*/
protected $dates = [
'created_at',
'updated_at'
];
/**
* @var array Relations
*/
public $hasOne = [];
public $hasMany = [];
public $belongsTo = [
'post' => [Post::class, 'post_id']
];
public $belongsToMany = [];
public $morphTo = [];
public $morphOne = [];
public $morphMany = [];
public $attachOne = [];
public $attachMany = [];
public function beforeDelete()
{
MediaLibrary::instance()->deleteFiles([$this->href]);
Event::fire('media.file.delete', [null, $this->href, null]);
}
}