12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Model;
- use Illuminate\Database\Eloquent\Model;
- use Carbon\Carbon;
- class Article extends Model
- {
- protected $table = 'articles';
- /**
- *
- */
- public function show($id = null)
- {
- if ($id) {
- return $this->where('id', '=', $id)->select(
- 'id', 'title as 标题', 'summary as 简介', 'body as 内容', 'author as 作者', 'status as 状态',
- 'img', 'type as 类型', 'order as 排序', 'resource as 来源',
- 'keys as 关键词', 'colid as 栏目ID', 'pushtime as 发布时间', 'count as 评论数量', 'atype as 展示类型'
- )->get();
- } else {
- return $this->select(
- 'id', 'title', 'summary', 'body', 'author', 'status',
- 'img', 'created_at', 'updated_at', 'type', 'order', 'resource',
- 'keys', 'colid', 'pushtime', 'count', 'atype'
- )->get();
- }
- }
- public function updates($id, $data)
- {
- return $this->where('id', '=', $id)->update($data);
- }
- public function del($id)
- {
- return $this->where('id', '=', $id)->delete();
- }
- public function inserts($data)
- {
- $time = Carbon::now();
- $data['created_at'] = $time;
- return $this->insert($data);
- }
- }
|