You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

7 years ago
  1. <?php
  2. namespace App\Http\Model;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Article extends Model
  5. {
  6. //文章模型
  7. /**
  8. * 关联到模型的数据表
  9. *
  10. * @var string
  11. */
  12. protected $table = 'article';
  13. /**
  14. * 表明模型是否应该被打上时间戳
  15. * 默认情况下,Eloquent 期望 created_at 和updated_at 已经存在于数据表中,如果你不想要这些 Laravel 自动管理的数据列,在模型类中设置 $timestamps 属性为 false
  16. *
  17. * @var bool
  18. */
  19. public $timestamps = false;
  20. //protected $guarded = []; //$guarded包含你不想被赋值的字段数组。
  21. //protected $fillable = ['name']; //定义哪些字段是可以进行赋值的,与$guarded相反
  22. /**
  23. * The connection name for the model.
  24. * 默认情况下,所有的 Eloquent 模型使用应用配置中的默认数据库连接,如果你想要为模型指定不同的连接,可以通过 $connection 属性来设置
  25. * @var string
  26. */
  27. //protected $connection = 'connection-name';
  28. /**
  29. * 文件上传
  30. * @param $field
  31. * @return string
  32. */
  33. public static function uploadImg($field)
  34. {
  35. if (Request::hasFile($field)) {
  36. $pic = Request::file($field);
  37. if ($pic->isValid()) {
  38. $newName = md5(rand(1, 1000) . $pic->getClientOriginalName()) . "." . $pic->getClientOriginalExtension();
  39. $pic->move('uploads', $newName);
  40. return $newName;
  41. }
  42. }
  43. return '';
  44. }
  45. /**
  46. * 获取关联到文章的分类
  47. */
  48. public function arctype()
  49. {
  50. return $this->belongsTo(Arctype::class, 'typeid', 'id');
  51. }
  52. }