Hello i want to ask laravel date compare. please telme this code is right. I want to check before login.
- When user Registered, user must be deactivated
- Admin must activate: end_date=activated_date 90 days
- Admin Deactive : end_date=deactivated_date;
- if current_date=deactivate_date
if ($user->activated_at ->gte(now()->subDays(90)))
{ return $this->sendError('messages.user_subscription', [], 400); }
CodePudding user response:
If do you want to check if $first is before or after $second
$first->isBefore($second);
or
$first->isAfter($second);
And if do you need to have diff, you can use
$first->diffInSeconds($second);
$first->diffInHours($second);
CodePudding user response:
Yes you code is correct, if it does not work you have to add activated_at in $dates in User model
.....
User extends Model
{
....
protected $dates = ['activated_at'];
....
/* Or
protected $casts = [
'activated_at' => 'datetime'
];
*/