first commit
This commit is contained in:
21
app/Models/Traits/BelongsToCategory.php
Normal file
21
app/Models/Traits/BelongsToCategory.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use App\Models\Category;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
trait BelongsToCategory
|
||||
{
|
||||
|
||||
/**
|
||||
* 关联分类表
|
||||
* @author 玄尘 2020-03-05
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Category::class)->withDefault();
|
||||
}
|
||||
|
||||
}
|
||||
24
app/Models/Traits/HasOneCover.php
Normal file
24
app/Models/Traits/HasOneCover.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
trait HasOneCover
|
||||
{
|
||||
|
||||
/**
|
||||
* 拼接图片全地址
|
||||
* @author 玄尘 2020-03-05
|
||||
* @return string
|
||||
*/
|
||||
public function getCoverPathAttribute(): ?string
|
||||
{
|
||||
if ($this->cover) {
|
||||
return Storage::url($this->cover);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user