|
@@ -10,21 +10,33 @@ class SitePageTag extends Model
|
|
use HasFactory;
|
|
use HasFactory;
|
|
protected $table = 'site_pages_tag';
|
|
protected $table = 'site_pages_tag';
|
|
|
|
|
|
- public function pages($perPage = 10)
|
|
|
|
|
|
+ public function pages($perPage = 10,$orderBy = null)
|
|
{
|
|
{
|
|
- return $this->belongsToMany(
|
|
|
|
- SitePage::class,
|
|
|
|
- 'site_pages_tag_relationship',
|
|
|
|
- 'tag_id',
|
|
|
|
- 'pages_id'
|
|
|
|
- )->where('status', 1)
|
|
|
|
- ->orderBy('post_date', 'desc')
|
|
|
|
- ->orderBy('id', 'desc')
|
|
|
|
- ->paginate($perPage); // 支持分页
|
|
|
|
|
|
+ if ($orderBy != null) {
|
|
|
|
+ $orderBy = explode(',', $orderBy);
|
|
|
|
+ return $this->belongsToMany(
|
|
|
|
+ SitePage::class,
|
|
|
|
+ 'site_pages_tag_relationship',
|
|
|
|
+ 'tag_id',
|
|
|
|
+ 'pages_id'
|
|
|
|
+ )->where('status', 1)
|
|
|
|
+ ->orderBy($orderBy[0], $orderBy[1])
|
|
|
|
+ ->paginate($perPage); // 支持分页
|
|
|
|
+ } else {
|
|
|
|
+ return $this->belongsToMany(
|
|
|
|
+ SitePage::class,
|
|
|
|
+ 'site_pages_tag_relationship',
|
|
|
|
+ 'tag_id',
|
|
|
|
+ 'pages_id'
|
|
|
|
+ )->where('status', 1)
|
|
|
|
+ ->orderBy('post_date', 'desc')
|
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
|
+ ->paginate($perPage); // 支持分页
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// 根据slug获取标签和关联的页面
|
|
// 根据slug获取标签和关联的页面
|
|
- public static function getBySlug($slug, $perPage = 10)
|
|
|
|
|
|
+ public static function getBySlug($slug, $perPage = 10,$orderBy = null)
|
|
{
|
|
{
|
|
$tag = self::where('slug', $slug)->where('dist_id', getDistId())->first();
|
|
$tag = self::where('slug', $slug)->where('dist_id', getDistId())->first();
|
|
|
|
|
|
@@ -33,6 +45,6 @@ class SitePageTag extends Model
|
|
}
|
|
}
|
|
|
|
|
|
// 获取与标签关联的页面
|
|
// 获取与标签关联的页面
|
|
- return $tag->pages($perPage);
|
|
|
|
|
|
+ return $tag->pages($perPage,$orderBy);
|
|
}
|
|
}
|
|
}
|
|
}
|