<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class SiteBanner extends Model { use HasFactory; protected $table = 'site_banner'; // 添加一个静态方法获取显示中的Banner(带position和默认值处理) public static function getBannerById($id, $position = 1) { return self::where('id', $id) ->where('show', 1) // 只获取 show = 1 的 Banner ->where('position', $position) // 根据 position 过滤 ->where('dist_id', getDistId()) // 根据 dist_id 过滤 ->first(); } // 添加一个静态方法获取符合条件的多个Banner public static function getBanners($position = 1, $limit = 10) { return self::where('show', 1) // 只获取 show = 1 的 Banner ->where('position', $position) // 根据 position 过滤 ->where('dist_id', getDistId()) // 根据 dist_id 过滤 ->limit($limit) ->get(); } }