RoomModel.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Models\Goodnight;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * App\Models\Goodnight\RoomModel
  6. *
  7. * @property int $id
  8. * @property string $name
  9. * @property int $activity_id
  10. * @property int $number
  11. * @property \Illuminate\Support\Carbon $created_at
  12. * @property \Illuminate\Support\Carbon $updated_at
  13. * @property int $interacted_at
  14. * @property-read \App\Models\Goodnight\ActivityModel $activity
  15. * @property-read \App\Models\Goodnight\RoomMessageModel $lastMessage
  16. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Goodnight\RoomMemberModel[] $members
  17. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel newModelQuery()
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel newQuery()
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel query()
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel whereActivityId($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel whereCreatedAt($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel whereId($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel whereInteractedAt($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel whereName($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel whereNumber($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Goodnight\RoomModel whereUpdatedAt($value)
  27. * @mixin \Eloquent
  28. */
  29. class RoomModel extends Model
  30. {
  31. //
  32. protected $table = 'kdgx_goodnight_rooms';
  33. protected $dateFormat = "U";
  34. protected $fillable = ['name', 'number', 'activity_id', 'interacted_at'];
  35. public function members()
  36. {
  37. return $this->hasMany(RoomMemberModel::class, 'room_id', 'id');
  38. }
  39. public function lastMessage()
  40. {
  41. return $this->hasOne(RoomMessageModel::class, 'room_id', 'id')->orderBy('created_at', 'desc');
  42. }
  43. public function activity()
  44. {
  45. return $this->belongsTo(ActivityModel::class);
  46. }
  47. }