ParentalControls.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. use App\User;
  7. use App\Services\AccountService;
  8. class ParentalControls extends Model
  9. {
  10. use HasFactory, SoftDeletes;
  11. protected $casts = [
  12. 'permissions' => 'array',
  13. 'email_sent_at' => 'datetime',
  14. 'email_verified_at' => 'datetime'
  15. ];
  16. protected $guarded = [];
  17. public function parent()
  18. {
  19. return $this->belongsTo(User::class, 'parent_id');
  20. }
  21. public function child()
  22. {
  23. return $this->belongsTo(User::class, 'child_id');
  24. }
  25. public function childAccount()
  26. {
  27. if($u = $this->child) {
  28. if($u->profile_id) {
  29. return AccountService::get($u->profile_id, true);
  30. } else {
  31. return [];
  32. }
  33. } else {
  34. return [];
  35. }
  36. }
  37. public function manageUrl()
  38. {
  39. return url('/settings/parental-controls/manage/' . $this->id);
  40. }
  41. public function inviteUrl()
  42. {
  43. return url('/auth/pci/' . $this->id . '/' . $this->verify_code);
  44. }
  45. }