Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 22
BirthdayNotifications
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 22
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 2
 handle
0.00% covered (danger)
0.00%
0 / 1
30
0.00% covered (danger)
0.00%
0 / 20
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Carbon\Carbon;
use App\Models\Auth\User;
use App\Notifications\AppNotifications;
class BirthdayNotifications extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'birthday:notifications';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'show birthday notification';
    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $users = User::all();
        $currentDate = Carbon::now()->format('m-d');
        $birthday_users = User::join('user_details', 'users.id', '=', 'user_details.user_id')
                                ->whereRaw('DATE_FORMAT(dob, "%m-%d") = ?', [$currentDate])
                                ->get();
        
        $title = "Birthday";
         if(!empty($birthday_users)){
          foreach($birthday_users as $birthday_user){
            //notification to user
           
            $userMessage =  'Wishing you a very Happy Birthday!!';
            $url = null;
            $arr = null;
            $arr = [$title, $userMessage, $url];
            User::find($birthday_user->user_id)->notify(new AppNotifications($arr));
            //notifiation to users
            foreach ($users as $user) {
                $message =  $birthday_user->name . ' ' . $birthday_user->lastName . "'s birthday today! ";
                $arr = null;
                $arr = [$title, $message, null];
                if($user->id  != $birthday_user->user_id){
                    $user->notify(new AppNotifications($arr));
                }
                
            }
        }
        
          
        }
    }
}