初步完成
This commit is contained in:
@@ -7,5 +7,12 @@ use App\Models\Traits\HasOneCover;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
|
||||
use HasOneCover, BelongsToCategory;
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('article.show', $this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\HasOneCover;
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
@@ -9,19 +10,24 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
|
||||
public const TYPES = [
|
||||
'article' => '文章列表',
|
||||
'show' => '文章详情',
|
||||
'advert' => '广告',
|
||||
'picture' => '图册',
|
||||
];
|
||||
use AdminBuilder, ModelTree, HasOneCover;
|
||||
|
||||
public const TYPE_SHOW = 'show';
|
||||
public const TYPE_ARTICLE = 'article';
|
||||
public const TYPE_ADVERT = 'advert';
|
||||
public const TYPE_PICTURE = 'picture';
|
||||
public const TYPE_PATENT = 'patent';
|
||||
public const TYPES = [
|
||||
self::TYPE_ARTICLE => '文章列表',
|
||||
self::TYPE_SHOW => '文章详情',
|
||||
self::TYPE_ADVERT => '图片',
|
||||
self::TYPE_PATENT => '专利',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('category.show', $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联的数据
|
||||
@@ -31,7 +37,7 @@ class Category extends Model
|
||||
{
|
||||
switch ($this->type) {
|
||||
case self::TYPE_SHOW:
|
||||
return $this->hasOne(Article::class,'id','article_id');
|
||||
return $this->hasOne(Article::class, 'id', 'article_id');
|
||||
break;
|
||||
case self::TYPE_ARTICLE:
|
||||
return $this->hasMany(Article::class);
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DedeAddonarticle extends Model
|
||||
{
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class DedeArchive extends Model
|
||||
{
|
||||
public function info()
|
||||
{
|
||||
return $this->hasOne(DedeAddonarticle::class, 'aid');
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Encore\Admin\Traits\AdminBuilder;
|
||||
use Encore\Admin\Traits\ModelTree;
|
||||
|
||||
class DedeArctype extends Model
|
||||
{
|
||||
use AdminBuilder, ModelTree;
|
||||
}
|
||||
26
app/Models/Patent.php
Normal file
26
app/Models/Patent.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Traits\BelongsToCategory;
|
||||
use App\Models\Traits\HasOneCover;
|
||||
|
||||
class Patent extends Model
|
||||
{
|
||||
|
||||
use HasOneCover, BelongsToCategory;
|
||||
|
||||
public const TYPE_PATENT = 'patent';
|
||||
public const TYPE_PAPER = 'paper';
|
||||
|
||||
public const TYPES = [
|
||||
self::TYPE_PATENT => '专利',
|
||||
self::TYPE_PAPER => '论文',
|
||||
];
|
||||
|
||||
public function getLinkAttribute()
|
||||
{
|
||||
return route('patents.show', $this);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user