LogLogin.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Modules\User\Models;
  3. use Illuminate\Contracts\Pagination\LengthAwarePaginator;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Psr\Container\ContainerExceptionInterface;
  6. use Psr\Container\NotFoundExceptionInterface;
  7. class LogLogin extends Model
  8. {
  9. protected $table = 'log_login';
  10. public $timestamps = false;
  11. protected $fillable = [
  12. 'id', 'account', 'login_ip', 'browser', 'platform', 'login_at', 'status',
  13. ];
  14. protected $casts = [
  15. 'login_at' => 'datetime:Y-m-d H:i'
  16. ];
  17. /**
  18. *
  19. * @param ?string $email
  20. * @return LengthAwarePaginator
  21. * @throws ContainerExceptionInterface
  22. * @throws NotFoundExceptionInterface
  23. */
  24. public function getUserLogBy(?string $email): LengthAwarePaginator
  25. {
  26. return static::when($email, function ($query) use ($email){
  27. $query->where('account', $email);
  28. })
  29. ->orderByDesc('id')
  30. ->paginate(request()->get('limit', 10));
  31. }
  32. }