<?php
namespace app\index\model;
use think\Model;
use think\Session;
class Forum 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 show()
{
$list = Forum::order('id desc')
->paginate(10);
return $list;
}
public static function view($id)
{
$view = Forum::find($id);
$view->comments = $view->comments()
->order('id desc')
->paginate(5);
return $view;
}
public function comment($value)
{
$content = Forum::find($value);
return $content;
}
public static function toadd($title,$content)
{
$user = new Forum;
$user->title = $title;
$user->content = $content;
$user->save();
return $user->id;
}
public static function add($title,$content,$user_id)
{
$user = new Forum;
$user->title = $title;
$user->content = $content;
$user->user_id = $user_id;
$user->save();
return $user->id;
}
public function comments()
{
return $this->hasMany('ForumComments','comment_id','id');
}
public function guomengtao()
{
return $this->hasMany('Comment','comment_id');
}
public function user()
{
return $this->hasOne('User','id','user_id');
}
}