AuthenticationLog.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * The MIT License (MIT)
  4. * Copyright (c) 2024 Bubka
  5. * Copyright (c) 2024 Anthony Rappa
  6. * Copyright (c) 2017 Yaakov Dahan
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  9. * associated documentation files (the "Software"), to deal in the Software without restriction,
  10. * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  18. * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  20. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. namespace App\Models;
  24. use Illuminate\Database\Eloquent\Model;
  25. use Illuminate\Database\Eloquent\Relations\MorphTo;
  26. /**
  27. * @property int $id
  28. * @property string $authenticatable_type
  29. * @property int $authenticatable_id
  30. * @property string|null $ip_address
  31. * @property string|null $user_agent
  32. * @property \Illuminate\Support\Carbon|null $login_at
  33. * @property bool $login_successful
  34. * @property \Illuminate\Support\Carbon|null $logout_at
  35. * @property bool $cleared_by_user
  36. * @property array|null $location
  37. * @property string|null $guard
  38. * @property string|null $method
  39. */
  40. class AuthenticationLog extends Model
  41. {
  42. /**
  43. * Indicates if the model should be timestamped.
  44. */
  45. public $timestamps = false;
  46. /**
  47. * The table associated with the model.
  48. */
  49. protected $table = 'authentication_log';
  50. /**
  51. * The attributes that are mass assignable.
  52. */
  53. protected $fillable = [
  54. 'ip_address',
  55. 'user_agent',
  56. 'login_at',
  57. 'login_successful',
  58. 'logout_at',
  59. 'cleared_by_user',
  60. 'location',
  61. 'guard',
  62. 'login_method',
  63. ];
  64. /**
  65. * The attributes that should be cast.
  66. */
  67. protected $casts = [
  68. 'cleared_by_user' => 'boolean',
  69. 'location' => 'array',
  70. 'login_successful' => 'boolean',
  71. 'login_at' => 'datetime',
  72. 'logout_at' => 'datetime',
  73. ];
  74. /**
  75. * Create a new Eloquent AuthenticationLog instance
  76. */
  77. public function __construct(array $attributes = [])
  78. {
  79. if (! isset($this->connection)) {
  80. $this->setConnection(config('authentication-log.db_connection'));
  81. }
  82. parent::__construct($attributes);
  83. }
  84. /**
  85. * Get the table associated with the model.
  86. */
  87. public function getTable()
  88. {
  89. return config('authentication-log.table_name', parent::getTable());
  90. }
  91. /**
  92. * MorphTo relation to get the associated authenticatable user
  93. *
  94. * @return MorphTo<\Illuminate\Database\Eloquent\Model, AuthenticationLog>
  95. */
  96. public function authenticatable()
  97. {
  98. return $this->morphTo();
  99. }
  100. }