laravel框架model类简单模板
来源:互联网 发布:网络电视盒刷机软件 编辑:程序博客网 时间:2024/05/20 06:40
class User extends Model{ //指定模型关联表 protected $table = 'user'; //指定数据库主键 protected $primaryKey = 'id'; //定义时间戳 public $timestamps = false; //定义时间戳格式 //protected $dateFormat = 'U'; //指定允许批量赋值的字段 protected $fillable = ['id','name','sort','status','author','user','clicks','created_at','updated_at']; //指定不允许批量赋值的字段 protected $guarded = []; private static $validate = [ //规则 'rule' => [ 'name' => 'required | min:3 | max:20 | string | unique:book', 'age' => 'required | integer', ], //提示信息 'message' => [ 'required' => ':attribute不能为空', 'min' => ':attribute字数太少了', 'max' => ':attribute字数太多了', 'string' => ':attribute格式错误', 'integer' => ':attribute必须为数字', 'unique' => '该:attribute已经存在', ], //自定义 'custom' => [ 'name' => '姓名', 'age' => '年龄' ] ]; public function validator($data) { return Validator::make( $data, self::$validate['rule'], self::$validate['message'], self::$validate['custom'] ); } //自定义时间存储格式 public static function boot() { parent::boot(); static::creating(function ($model) { $date = date('Y-m-d H:i:s'); $model->created_at = $date; $model->updated_at = $date; return true; }); static::updating(function ($model) { $date = date('Y-m-d H:i:s'); $model->updated_at = $date; return true; }); } //获取格式化好的时间戳 protected function getDateFormat() { return time(); } //没有格式化好的时间 protected function asDateTime($val) { return $val; }}
阅读全文
0 0
- laravel框架model类简单模板
- laravel框架中使用model层
- laravel框架中使用model层
- laravel框架简单文件上传
- laravel框架-session简单使用
- 对laravel框架中的Eloquent model的一点认识
- Laravel在model类里关闭timestamps
- laravel框架里简单的操作
- Laravel框架中简单使用中间件
- laravel框架-实现简单的文件上传
- Laravel中创建Model
- laravel Model模型
- Laravel Model数据操作
- Laravel Model数据操作
- laravel Model 执行事务
- laravel 生成model
- laravel model relationship
- laravel model 两表联查
- centos7 虚拟机桥接设置
- android 输入首字符,提示信息,并进行选择显示在搜索框
- 基于NFS和autofs的LAMP
- ios-实现二维码扫描功能
- EM算法--ML之六
- laravel框架model类简单模板
- 人工智能-语音交互-NLP自然语言(五)
- 最长回文子串-简单版本
- Vue2.x和webpack踩坑与总结
- Error:Failed to open zip file. Gradle's dependency cache may be corrupt (this sometimes occurs after
- linux驱动实例
- mobiscroll时间插件的用法
- 第一周学习总结
- 【末世旅行之逆向破解】破解三国杀脚本,免注册码无限时间全功能使用