模型

webman默认使用的laravel-orm

<?php


namespace app\api\Message\model;


use support\Model;
// 引入软删除依赖
use Illuminate\Database\Eloquent\SoftDeletes;


/**
 *
 */
class Message extends Model
{
    // 使用软删除
    use SoftDeletes;


    // 设置模型关联表名
    protected $table = 'message';


    // 设置表主键字段
    protected $primaryKey = 'id';


    /**
     * 设置是否开启自动写入时间,默认为false
     * 设置为true后默认数据表中有created_at和updated_at字段,没有则会报错
     * 如需自定义存储时间戳的字段名,可以设置 CREATED_AT 和 UPDATED_AT 常量的值来实现
     * 默认软删除字段值:delete_at(默认数据表已有该字段),若需自定义也是看下面
     */
    public $timestamps = true;




    const CREATED_AT = 'create_time';
    const UPDATED_AT = 'update_time';
    const DELETED_AT = "delete_time"; //软删除字段


    //默认情况下自动写入库的格式为y-m-d h:i:s,若需要时间戳则需要定义下面这条
    protected $dateFormat = 'U';


    // 下面即是允许入库的字段,不设置则报错
    protected $fillable = ['name', 'email', 'content'];


    // 下面用于设置不允许入库字段,一般和$fillable存在一个即可
    // protected $guarded = [];
}


posted @ 2024-07-09 15:59  Anbin啊  阅读(16)  评论(0)    收藏  举报