标签:
路由
Route::resource(‘articles‘,‘ArticleController‘);
model
class Article extends Model { //添加可填充的字段 protected $fillable = [ ‘title‘, ‘body‘, ‘publishedAt‘ ]; //修改被提交的字段属性 public function setPublishedAtAttribute($date) { $this->attributes[‘publishedAt‘] = Carbon::createFromFormat(‘Y-m-d‘, $date); } //自定义查询条件,在控制器中引用 public function scopePublished($query) { $query->where(‘publishedAt‘, ‘<=‘, Carbon::now()); } public function scopeUnPublished($query) { $query->where(‘publishedAt‘, ‘>‘, Carbon::now()); } }
标签:
原文地址:http://www.cnblogs.com/fenle/p/4799715.html