2019-07-11 11:45:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
2019-09-12 11:08:25 +02:00
|
|
|
namespace App\Models;
|
2019-07-11 11:45:47 +02:00
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2022-08-01 16:27:22 +02:00
|
|
|
use Rennokki\QueryCache\Traits\QueryCacheable;
|
2019-07-11 11:45:47 +02:00
|
|
|
|
|
|
|
|
class Article extends Model
|
|
|
|
|
{
|
2022-08-01 16:27:22 +02:00
|
|
|
use QueryCacheable;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The timeout cache for this model
|
|
|
|
|
*
|
|
|
|
|
* @var integer
|
|
|
|
|
*/
|
|
|
|
|
protected $cacheFor = -1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The cache driver to be used.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public $cacheDriver = 'redis';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform any actions required after the model boots.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
|
|
|
static::created(function (self $model) {
|
|
|
|
|
// * Flush Eloquent cache.
|
|
|
|
|
self::flushQueryCache();
|
|
|
|
|
});
|
|
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
|
|
|
static::updated(function (self $model) {
|
|
|
|
|
// * Flush Eloquent cache.
|
|
|
|
|
self::flushQueryCache();
|
|
|
|
|
});
|
|
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
|
|
|
|
static::deleted(function (self $model) {
|
|
|
|
|
// * Flush Eloquent cache.
|
|
|
|
|
self::flushQueryCache();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// * Laravel Behaviors
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the base cache tags that will be present
|
|
|
|
|
* on all queries.
|
|
|
|
|
*
|
|
|
|
|
* ! This is used to flush caching
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
protected function getCacheBaseTags(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'dam_article',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 14:57:58 +02:00
|
|
|
// * RELATIONSHIPS
|
|
|
|
|
|
2022-04-19 16:07:27 +02:00
|
|
|
/**
|
2022-06-20 14:57:58 +02:00
|
|
|
* BelongsToMany mediaList relation
|
|
|
|
|
*
|
|
|
|
|
* The mediaList that belong to the article.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
2022-04-19 16:07:27 +02:00
|
|
|
*/
|
2022-06-20 14:57:58 +02:00
|
|
|
public function mediaList()
|
2022-04-19 16:07:27 +02:00
|
|
|
{
|
2025-11-28 17:20:03 +01:00
|
|
|
return $this->belongsToMany(Media::class, 'media_article', 'article_id', 'media_id');
|
2022-04-19 16:07:27 +02:00
|
|
|
}
|
2019-07-11 11:45:47 +02:00
|
|
|
}
|