<?php
namespace app\index\model;
use think\Model;
use think\Session;
class User extends Model
{
protected $autoWriteTimestamp = 'int';
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
public function getcreatetimeAttr($value, $data)
{
$value = $value ? $value : (isset($data['refreshtime']) ? $data['createtime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public static function self()
{
$list = Blog::order('id desc')->paginate(5);
return $list;
}
public static function blogview($id)
{
$blogview = Blog::get($id);
$blogview->blogcomments = $blogview->comments()
->where('category',2)
->where('status','normal')
->order('id desc')
->paginate(5);
return $blogview;
}
public function comments()
{
return $this->hasMany('Comment','comment_id','id');
}
}