oc-social-plugin/models/Attachment.php

83 lines
1.8 KiB
PHP
Raw Normal View History

2021-10-28 22:35:15 +02:00
<?php namespace Zoomyboy\Social\Models;
use Event;
2021-10-30 12:16:27 +02:00
use Media\Classes\MediaLibrary;
use Model;
2021-10-28 22:35:15 +02:00
/**
* 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
*/
2021-10-30 12:16:27 +02:00
protected $fillable = [ 'remote_id', 'post_id', 'href', 'type' ];
2021-10-28 22:35:15 +02:00
/**
* @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]);
}
}