59 lines
1.3 KiB
PHP
59 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\HasThumbnail;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class Image extends Model implements HasThumbnail
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The model's default values for attributes.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $attributes = [
|
|
'isCover' => false,
|
|
'lightboxWidth' => 0,
|
|
'lightboxHeight' => 0,
|
|
];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = ['album_id', 'lightboxWidth', 'lightboxHeight'];
|
|
|
|
public function album(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Album::class);
|
|
}
|
|
|
|
public function getThumbnail() : string {
|
|
return route('image.thumbnail', $this);
|
|
}
|
|
|
|
public function getDownload() : string {
|
|
return route('image.download', $this);
|
|
}
|
|
|
|
public function setLightboxSize(int $width, int $height) : void {
|
|
$this->lightboxWidth = $width;
|
|
$this->lightboxHeight = $height;
|
|
$this->save();
|
|
}
|
|
|
|
public function getLightboxAttribute() : array {
|
|
return [
|
|
'location' => route('image.lightbox', $this),
|
|
'width' => $this->lightboxWidth,
|
|
'height' => $this->lightboxHeight,
|
|
];
|
|
}
|
|
}
|