需要检查用户在我的网站上注册了多长时间 Laravel 5.2

Need to check how long a user has been registered on my site Laravel 5.2

我正在我的网站上做一个奖励系统,我想将徽章奖励给在我的网站上注册了一个月的用户,然后是几年。我将如何在 Laravel 5.2 中执行此操作?我的用户 table.

已经有一个 created_at

************ 编辑 ******************

好的,所以我需要在视图中显示它,类似于:

            @if ($user->difference <= 30)
                <img src="{{ ShowSignedUpFor30days }}" class="ui small circular image" id="Badge">
            @else

            @endif

           @if ($user->difference <= 30)
                <img src="{{ ShowSignedUpFor300days }}" class="ui small circular image" id="Badge">
            @else

            @endif

正如您在 table 中看到的那样,您可以使用 created_at 字段来了解用户的创建时间。

您可以在用户模型中创建与此类似的函数来创建徽章。 (未测试)

public function userSinceInDays(){

  $created = $this->created_at;
  $now = Carbon::now();
  $difference = $created->diff($now)->days;

  return $difference;

}

您可以访问

 @if ($user->userSinceInDays() <= 30)
     <img src="{{ ShowSignedUpFor30days }}" class="ui small circular image" id="Badge">
 @endif

 @if ($user->userSinceInDays() >= 300)
     <img src="{{ ShowSignedUpFor300days }}" class="ui small circular image" id="Badge">
 @endif