<?php
namespace app\index\model;
use think\Model;
use think\Session;
class Bbsdemo 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 bbs()
{
$list = Bbsdemo::order('id desc')
->paginate(10);
return $list;
}
public static function bbsdemo()
{
$list = Bbsdemo::order('id desc')->paginate(10);
return $list;
}
public static function bbsview($id)
{
$bbsview = Bbsdemo::find($id);
$bbsview->bbscomments = $bbsview->comments()
->where('category',1)
->where('status','normal')
->order('id desc')
->paginate(5);
return $bbsview;
}
public function bbscomment($value)
{
$bbsview = Bbsdemo::find($value);
$bbsview = $bbsview->comments()->where('category',1)->select();
return $bbsview;
}
public static function toadd($title,$content)
{
$user = new Bbsdemo;
$user->title = $title;
$user->content = $content;
$user->save();
return $user->id;
}
public static function add($title,$content)
{
$user = new Bbsdemo;
$user->title = $title;
$user->content = $content;
$user->save();
return $user->id;
}
public function comments()
{
return $this->hasMany('Comment','comment_id','id');
}
public function guomengtao()
{
return $this->hasMany('Comment','comment_id');
}
}