修改广告位和广告模型
parent
2054d5e749
commit
3fa1e4692d
|
|
@ -3,17 +3,23 @@
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Ad extends Model
|
class Ad extends Model
|
||||||
{
|
{
|
||||||
|
use Concerns\HasShowable;
|
||||||
use HasDateTimeFormatter;
|
use HasDateTimeFormatter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'is_show' => 'boolean',
|
'is_show' => 'bool',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 此广告所属的广告位
|
||||||
|
*/
|
||||||
public function address()
|
public function address()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(AdAddress::class, 'address_id');
|
return $this->belongsTo(AdAddress::class, 'address_id');
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,23 @@
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class AdAddress extends Model
|
class AdAddress extends Model
|
||||||
{
|
{
|
||||||
|
use Concerns\HasShowable;
|
||||||
use HasDateTimeFormatter;
|
use HasDateTimeFormatter;
|
||||||
protected $table = 'ad_addresses';
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'is_show' => 'boolean',
|
'is_show' => 'bool',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 属于此广告位的广告
|
||||||
|
*/
|
||||||
public function ads()
|
public function ads()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Ad::class, 'address_id');
|
return $this->hasMany(Ad::class, 'address_id');
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Concerns;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
trait HasShowable
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 只查询可显示的数据
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function scopeShowable(Builder $query): Builder
|
||||||
|
{
|
||||||
|
return $query->where('is_show', true);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue