app/Console/Commands/NotifyBirthdays.php
/**
     * Execute the console command.
     *
     * @return mixed
     */
Execute the console command.
@return mixed
Execute the console command . @return mixed
public function handle()
    {
        $daysBefore = 3;
        $users = User::whereHas('profile', function ($query) use ($daysBefore) {
            $query->where(\DB::raw('MOD(DAYOFYEAR(birth_date) - DAYOFYEAR(CURRENT_DATE()) + 366, 366)'), $daysBefore);
        })->get();
        foreach ($users as $user) {
            foreach ($user->friends as $friend) {
                event(new NotificationEvent($user->profile, $friend, ['type' => 'birthday']));
            }
            $this->output->comment("{$user->profile->full_name} has birthday in $daysBefore days, "
                                   . "sent notifications to " . count($user->friends) . " friends");
        }
    }
public function handle ( ) { $ daysBefore = 3 ; $ users = User :: whereHas ( 'profile' , function ( $ query ) use ( $ daysBefore ) { $ query -> where ( \ DB :: raw ( 'MOD(DAYOFYEAR(birth_date) - DAYOFYEAR(CURRENT_DATE()) + 366, 366)' ) , $ daysBefore ) ; } ) -> get ( ) ; foreach ( $ users as $ user ) { foreach ( $ user -> friends as $ friend ) { event ( new NotificationEvent ( $ user -> profile , $ friend , [ 'type' => 'birthday' ] ) ) ; } $ this -> output -> comment ( " { $ user -> profile -> full_name }  has birthday in  $ daysBefore  days,  " . " sent notifications to  " . count ( $ user -> friends ) . "  friends " ) ; } }
Execute the console command.
Execute the console command .