feat: add community post categories and channels
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace app\adminapi\validate\community;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\community\CommunityCategory;
|
||||
use app\common\model\community\CommunityPost;
|
||||
|
||||
class CommunityPostValidate extends BaseValidate
|
||||
@@ -13,6 +14,8 @@ class CommunityPostValidate extends BaseValidate
|
||||
'is_top' => 'require|in:0,1',
|
||||
'is_hot' => 'require|in:0,1',
|
||||
'is_recommend' => 'require|in:0,1',
|
||||
'is_topic' => 'require|in:0,1',
|
||||
'category_id' => 'require|integer|egt:0|checkCategory',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
@@ -50,6 +53,16 @@ class CommunityPostValidate extends BaseValidate
|
||||
return $this->only(['id', 'is_recommend']);
|
||||
}
|
||||
|
||||
public function sceneTopic()
|
||||
{
|
||||
return $this->only(['id', 'is_topic']);
|
||||
}
|
||||
|
||||
public function sceneCategory()
|
||||
{
|
||||
return $this->only(['id', 'category_id']);
|
||||
}
|
||||
|
||||
public function checkPost($value)
|
||||
{
|
||||
$post = CommunityPost::findOrEmpty($value);
|
||||
@@ -58,4 +71,16 @@ class CommunityPostValidate extends BaseValidate
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkCategory($value)
|
||||
{
|
||||
if ((int) $value === 0) {
|
||||
return true;
|
||||
}
|
||||
$category = CommunityCategory::where('id', $value)->where('status', 1)->findOrEmpty();
|
||||
if ($category->isEmpty()) {
|
||||
return '帖子分类不存在或已禁用';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user