34 lines
709 B
PHP
34 lines
709 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Traits\BelongsToCategory;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class ArticlePicture extends Model
|
|
{
|
|
use BelongsToCategory;
|
|
|
|
public function setPicturesAttribute($pictures)
|
|
{
|
|
if (is_array($pictures)) {
|
|
$this->attributes['pictures'] = json_encode($pictures);
|
|
}
|
|
}
|
|
|
|
public function getPicturesAttribute($pictures)
|
|
{
|
|
return json_decode($pictures, true);
|
|
}
|
|
|
|
public function getOnePicturePathAttribute(): string
|
|
{
|
|
$cover = $this->pictures;
|
|
if (empty($cover)) {
|
|
return '';
|
|
} else {
|
|
return Storage::disk('public')->url($cover[0]);
|
|
}
|
|
}
|
|
}
|