92 lines
2.0 KiB
PHP
92 lines
2.0 KiB
PHP
<?php namespace Zoomyboy\Social\Models;
|
|
|
|
use Model;
|
|
use System\Classes\MediaLibrary;
|
|
|
|
/**
|
|
* Page Model
|
|
*/
|
|
class Page extends Model
|
|
{
|
|
use \October\Rain\Database\Traits\Validation;
|
|
use \October\Rain\Database\Traits\Sluggable;
|
|
|
|
/**
|
|
* @var string The database table used by the model.
|
|
*/
|
|
public $table = 'zoomyboy_social_pages';
|
|
|
|
public $slugs = ['slug' => 'name'];
|
|
|
|
public static array $pageTypes = [
|
|
'facebook' => 'Facebook',
|
|
'instagram' => 'Instagram',
|
|
];
|
|
|
|
/**
|
|
* @var array Guarded fields
|
|
*/
|
|
protected $guarded = ['*'];
|
|
|
|
/**
|
|
* @var array Fillable fields
|
|
*/
|
|
protected $fillable = ['name', 'type', 'cover', 'slug', 'access_token', 'remote_id'];
|
|
|
|
/**
|
|
* @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'
|
|
];
|
|
|
|
public $hasMany = [
|
|
'posts' => [ Post::class, 'page_id' ]
|
|
];
|
|
|
|
public function getMediaPathAttribute() {
|
|
return 'social/facebook/'.$this->slug.'/';
|
|
}
|
|
|
|
public function beforeDelete() {
|
|
$this->posts->each->delete();
|
|
|
|
MediaLibrary::instance()->deleteFolder($this->mediaPath);
|
|
}
|
|
|
|
public static function select($type = null): array
|
|
{
|
|
if (is_null($type)) {
|
|
return static::get()->pluck('name', 'id')->toArray();
|
|
}
|
|
|
|
return static::whereType($type)->get()->pluck('name', 'id')->toArray();
|
|
}
|
|
}
|