firstpush
This commit is contained in:
15
app/Models/Advert.php
Normal file
15
app/Models/Advert.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use App\Models\Traits\OrderByIdDesc;
|
||||
use App\Scopes\SortScope;
|
||||
|
||||
class Advert extends Model
|
||||
{
|
||||
|
||||
use HasOneCover,
|
||||
BelongsToCategory;
|
||||
}
|
||||
11
app/Models/Article.php
Normal file
11
app/Models/Article.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
use HasOneCover, BelongsToCategory;
|
||||
}
|
||||
33
app/Models/ArticlePicture.php
Normal file
33
app/Models/ArticlePicture.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
57
app/Models/Category.php
Normal file
57
app/Models/Category.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
|
||||
public const TYPES = [
|
||||
'article' => '文章列表',
|
||||
'show' => '文章详情',
|
||||
'advert' => '广告',
|
||||
'picture' => '图册',
|
||||
];
|
||||
|
||||
public const TYPE_SHOW = 'show';
|
||||
public const TYPE_ARTICLE = 'article';
|
||||
public const TYPE_ADVERT = 'advert';
|
||||
public const TYPE_PICTURE = 'picture';
|
||||
|
||||
/**
|
||||
* 关联的数据
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function relations()
|
||||
{
|
||||
switch ($this->type) {
|
||||
case self::TYPE_SHOW:
|
||||
return $this->hasOne(Article::class,'id','article_id');
|
||||
break;
|
||||
case self::TYPE_ARTICLE:
|
||||
return $this->hasMany(Article::class);
|
||||
break;
|
||||
case self::TYPE_ADVERT:
|
||||
return $this->hasMany(Advert::class);
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(__CLASS__)->withDefault(['name' => '顶级分类']);
|
||||
}
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(__CLASS__, 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
7
app/Models/DedeAddonarticle.php
Normal file
7
app/Models/DedeAddonarticle.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DedeAddonarticle extends Model
|
||||
{
|
||||
}
|
||||
11
app/Models/DedeArchive.php
Normal file
11
app/Models/DedeArchive.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DedeArchive extends Model
|
||||
{
|
||||
public function info()
|
||||
{
|
||||
return $this->hasOne(DedeAddonarticle::class, 'aid');
|
||||
}
|
||||
}
|
||||
11
app/Models/DedeArctype.php
Normal file
11
app/Models/DedeArctype.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
|
||||
class DedeArctype extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
}
|
||||
8
app/Models/Link.php
Normal file
8
app/Models/Link.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Link extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
22
app/Models/Model.php
Normal file
22
app/Models/Model.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace App\Models;
|
||||
|
||||
use DateTimeInterface;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
|
||||
class Model extends Eloquent
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
/**
|
||||
* 为数组 / JSON 序列化准备日期。
|
||||
*
|
||||
* @param \DateTimeInterface $date
|
||||
* @return string
|
||||
*/
|
||||
protected function serializeDate(DateTimeInterface $date)
|
||||
{
|
||||
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
|
||||
}
|
||||
|
||||
}
|
||||
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