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.

40 lines
928 B

  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Invite extends Model
  5. {
  6. public $primaryKey = 'code';
  7. protected $keyType = 'string';
  8. public $incrementing = false;
  9. protected $fillable = ['code'];
  10. public function user()
  11. {
  12. return $this->belongsTo('App\User');
  13. }
  14. public function room()
  15. {
  16. return $this->hasOne('App\Contact', 'id', 'resource');
  17. }
  18. public static function set($jid, $resource)
  19. {
  20. $invitation = \App\Invite::where('user_id', $jid)
  21. ->where('resource', $resource)
  22. ->first();
  23. if (!$invitation) {
  24. $invitation = new \App\Invite;
  25. $invitation->code = generateKey(8);
  26. $invitation->user_id = $jid;
  27. $invitation->resource = $resource;
  28. $invitation->save();
  29. }
  30. return $invitation;
  31. }
  32. }