skip to Main Content

I have small problem in app. Backend is Laravel and Front end is Nuxtjs.
When User registered on app,then users must be wait antill Administartor approved.
When Admin approved this user we give them 3 months subscription.

In my code this part is not working.

$user->activated_at = now();
       $user->activated_at = date('Y-m-d H:i');
   {
       $user = User::find($id);
       if (is_null($user)) {
           return $this->sendError('admin_messages.user_not_found');
       }
       $user->status = User::ACTIVE;
       $user->activated_at = now();
       $user->activated_at = date('Y-m-d H:i');
       dd($user->activated_at);
       $user->save();
       Mail::to($user->email)->queue(new ApproveNotificationMail($user));
       return $this->sendResponse('admin_messages.user_activated');
   }

2

Answers


  1. You can use mutator in your User model, to force activated_at format:

    public function setActivatedAtAttribute( $value ) {
    $this->attributes['activated_at'] = (new Carbon($value))->format('Y-m-d H:i'); 
    }
    

    You can define a format for date columns using:

    protected $dateFormat = 'Y-m-d H:i';
    

    Note that you can directly use:

    $user->activated_at = CarbonCarbon::now()->format('Y-m-d H:i'); 
    
    Login or Signup to reply.
  2.    
     $user->activated_at = CarbonCarbon::now()->format('Y-m-d H:i');
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search