zoukankan      html  css  js  c++  java
  • laravel blog 一

    路由

    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());
        }
    }
    

     处理请求,对提交的数据进行验证

    <?php
    
    namespace AppHttpRequests;
    
    use AppHttpRequestsRequest;
    
    class ArticleRequest extends Request
    {
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize()
        {
            return true;
        }
    
        /**
         * Get the validation rules that apply to the request.
         *
         * @return array
         */
        public function rules()
        {
            return [
                'title' => 'required|min:3',
                'body' => 'required',
                'publishedAt' => 'required|date'
            ];
        }
    }
    
  • 相关阅读:
    Winfrom 动画实现
    Android-SD卡相关操作
    Android-动态权限获取
    Java 常用知识点
    无锁队列的实现
    稳定的快排
    设计模式
    map的线程安全
    win 消息
    memecpy源码
  • 原文地址:https://www.cnblogs.com/fenle/p/4799715.html
Copyright © 2011-2022 走看看