mirror of
https://github.com/ProxyPanel/ProxyPanel.git
synced 2026-04-03 11:09:27 +00:00
1. 继续修改表表关系,与关联字段的限制; 2. 通过表表关系,简化一部分代码,自动让Laravel建立关联; 3. 拆分验证 与 优化数据创建与修改的获取数据操作; 4. 修改部分无意义的数据名称;
36 lines
753 B
PHP
36 lines
753 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
/**
|
|
* 优惠券.
|
|
*/
|
|
class Coupon extends Model
|
|
{
|
|
use SoftDeletes;
|
|
|
|
protected $table = 'coupon';
|
|
protected $casts = ['start_time' => 'date:Y-m-d', 'end_time' => 'date:Y-m-d'];
|
|
protected $dates = ['deleted_at'];
|
|
protected $guarded = [];
|
|
|
|
// 筛选类型
|
|
public function scopeType($query, $type)
|
|
{
|
|
return $query->whereType($type);
|
|
}
|
|
|
|
public function setStartTimeAttribute($value)
|
|
{
|
|
return $this->attributes['start_time'] = strtotime($value);
|
|
}
|
|
|
|
public function setEndTimeAttribute($value)
|
|
{
|
|
return $this->attributes['end_time'] = strtotime($value);
|
|
}
|
|
}
|