Home > Back-end >  Laravel Date assign errorr
Laravel Date assign errorr

Time:10-20

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');
   }

CodePudding user response:

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 = \Carbon\Carbon::now()->format('Y-m-d H:i'); 

CodePudding user response:

   
 $user->activated_at = \Carbon\Carbon::now()->format('Y-m-d H:i');

  • Related