<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
astrotomic / laravel-cachable-attributes example snippets
class Gallery extends Model
{
public function images(): HasMany
{
return $this->hasMany(Image::class, 'gallery_id');
}
public function getStorageSizeAttribute(): int
{
return $this->images()->sum('file_size');
}
}
use Astrotomic\CachableAttributes\CachableAttributes;
use Astrotomic\CachableAttributes\CachesAttributes;
class Gallery extends Model implements CachableAttributes
{
use CachesAttributes;
protected $cachableAttributes = [
'storage_size',
];
public function images(): HasMany
{
return $this->hasMany(Image::class, 'gallery_id');
}
public function getStorageSizeAttribute(): int
{
return $this->remember('storage_size', 0, function(): int {
return $this->images()->sum('file_size');
});
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.