Article.php 746 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Models\Blog;
  3. use App\Models\Base\BaseModel;
  4. class Article extends BaseModel
  5. {
  6. //
  7. protected $table = 'blog_articles';
  8. protected $fillable = ['slug', 'title', 'keywords', 'description', 'markdown', 'user_id', 'cate_id'];
  9. //
  10. public function category()
  11. {
  12. return $this->belongsTo(Category::class, 'cate_id', 'id');
  13. }
  14. public function checkStore($data)
  15. {
  16. $validData = array();
  17. foreach ($this->fillable as $key) {
  18. if (isset($data[$key])) {
  19. $validData[$key] = $data[$key];
  20. } elseif (!in_array($key, $this->allowEmpty)) {
  21. return 0;
  22. }
  23. }
  24. return $this->fill($validData)->save();
  25. }
  26. }