🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
当前是BPost表模型: ``` <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use \App\Models\Model; class BPost extends Model { use HasFactory; protected $table = "b_posts"; /* * BPost表文章用户id对应的用户数据 */ public function bUser() { return $this->belongsTo('App\Models\BUser', 'b_user_id', 'id'); } /* * 当前文章的所有分类 */ public function categories() { return $this->belongsToMany(\App\Models\BPostCategory::class, 'b_post_category_relationships', 'b_post_id', 'b_category_id'); // return $this->belongsToMany(\App\Models\BPostCategory::class, 'b_post_category_relationships', 'b_post_id', 'b_category_id')->withPivot(['b_post_id', 'b_category_id']); } /* * 文章是否有分类 */ public function hascategory($category) { return $this->categories->contains($category); } } ```