samedi 15 mai 2021

cant get this to work on my code i dont know why, I am getting the following error: below

i am trying Edujugon Push Notification laravel; all configuration be correct. my push notification code is bellow the error i got

Whoops, looks like something went wrong.

FatalThrowableError in SendPushNotification.php line 402: Class 'Edujugon\PushNotification\PushNotification' not found

        <?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
use App\ProviderDevice;
use App\ProviderService;
use Exception;
use Log;
use Setting;
use Edujugon\PushNotification\PushNotification;

class SendPushNotification extends Controller
{
    
    public function RideAccepted($request){

        return $this->sendPushToUser($request->user_id, trans('api.push.request_accepted'), 'accepted');
    }

   
    public function RideAcceptedRemainProviders($request,$provider){

        return $this->sendPushToProvider($request->provider_id, 'Current ride request has been Accepted by '.$provider->first_name.'-'.$provider->service->service_number);
    }
    
    public function RideCancelledAllProviders($request,$user_name){

        return $this->sendPushToProvider($request->provider_id, 'User cancelled the request');
    }

   
    public function AdminApproveProvider($provider){

        return $this->sendPushToProvider($provider->id, 'Admin approved your account to ride SERVICE NAME :'.$provider->service->service_type->name);
    }

   
    public function AdminDisapproveProvider($provider){

        return $this->sendPushToProvider($provider->id, 'Admin disapproved your account to ride SERVICE NAME :'.$provider->service->service_type->name);
    }


    
    public function user_schedule($user){

        return $this->sendPushToUser($user, trans('api.push.schedule_start'));
    }

   
    public function provider_schedule($provider){

        return $this->sendPushToProvider($provider, trans('api.push.schedule_start'));

    }

   
    public function UserCancellRide($request){

        return $this->sendPushToProvider($request->provider_id, trans('api.push.user_cancelled'));
    }


    public function ProviderCancellRide($request){

        return $this->sendPushToUser($request->user_id, trans('api.push.provider_cancelled'));
    }

   
    public function Arrived($request){

        return $this->sendPushToUser($request->user_id, trans('api.push.arrived'), 'arrived');
    }

   
    public function Pickedup($request){

        return $this->sendPushToUser($request->user_id, trans('api.push.pickedup'), 'pickedup');
    }

   
    public function Dropped($request){

        Log::info( trans('api.push.dropped').Setting::get('currency').$request->payment->total.' by '.$request->payment_mode);

        return $this->sendPushToUser($request->user_id, trans('api.push.dropped').Setting::get('currency').$request->payment->total.' by '.$request->payment_mode, 'dropped');
    }

   
    public function Complete($request){

        return $this->sendPushToUser($request->user_id, trans('api.push.complete'), 'completed');
    }

    
     
   
    public function Rate($request){

        return $this->sendPushToUser($request->user_id, trans('api.push.rate'));
    }



    public function ProviderNotAvailable($user_id){

        return $this->sendPushToUser($user_id,trans('api.push.provider_not_available'));
    }

   
  
    public function IncomingRequest($provider, $voip=false){

        $this->sendPushToProvider($provider, trans('api.push.incoming_request'), 'searching');

    } 
    

 
    public function DocumentsVerfied($provider_id){

        return $this->sendPushToProvider($provider_id, trans('api.push.document_verfied'));
    }


    /**
     * Money added to user wallet.
     *
     * @return void
     */
    public function WalletMoney($user_id, $money){

        return $this->sendPushToUser($user_id, $money.' '.trans('api.push.added_money_to_wallet'));
    }

  
    public function ChargedWalletMoney($user_id, $money){

        return $this->sendPushToUser($user_id, $money.' '.trans('api.push.charged_from_wallet'));
    }

  
    public function sendPushToUser($user_id, $push_message,$sound="default"){

        try{

            // $user = User::findOrFail($user_id);


      //       if($user->device_token != ""){

      //           \Log::info('sending push for user : '. $user->first_name);

         //     if($user->device_type == 'ios'){

         //         return \PushNotification::app('IOSUser')
            //             ->to($user->device_token)
            //             ->send($push_message, array('sound' => $sound.'.caf'));

         //     }elseif($user->device_type == 'android'){
                    
         //         return \PushNotification::app('AndroidUser') 
      //                   ->to($user->device_token)
      //                   ->send($push_message, array('sound' => $sound));
                       

         //     }
      //       }



            $user = User::findOrFail($user_id);


            if($user->device_token != ""){

               \Log::info('sending push for user : '. $user->first_name);
                \Log::info($push_message);

                if($user->device_type == 'ios'){
                     if(env('IOS_USER_ENV')=='development'){
                        $crt_user_path=app_path().'/apns/user/enterprise_user.pem';
                        $crt_provider_path=app_path().'/apns/user/enterprise_user.pem';
                        $dry_run = true;
                    }
                   else{
                         $crt_user_path=app_path().'/apns/user/enterprise_user.pem';
                        $crt_provider_path=app_path().'/apns/user/enterprise_user.pem';
                        $dry_run = false;
                    }
                    
                   $push = new PushNotification('apn');

                    $push->setConfig([
                            'certificate' => $crt_user_path,
                            'passPhrase' => env('IOS_USER_PUSH_PASS', 'apple'),
                            'dry_run' => $dry_run
                        ]);

                   $send=  $push->setMessage([
                            'aps' => [
                                'alert' => [
                                    'body' => $push_message
                                ],
                                'sound' => 'default',
                                'badge' => 1

                            ],
                            'extraPayLoad' => [
                                'custom' => $push_message
                            ]
                        ])
                        ->setDevicesToken($user->device_token)->send();
                        \Log::info('sent');
                    
                    return $send;

                }elseif($user->device_type == 'android'){

                   $push = new PushNotification('fcm');
                   $send=  $push->setMessage(['message'=>$push_message])
                        ->setDevicesToken($user->device_token)->send();
                    
                    return $send;
                       

                }
            }

        } catch(Exception $e){
            return $e;
        }

    }

    
    public function sendPushToProvider($provider_id, $push_message){

        try{

                    // if($voip == true)
                    // {
                    //     \Log::info('voip token');
                        
                    //     \PushNotification::app('IOSProviderVoip')
                    //         ->to($provider->voip_token)
                    //         ->send($push_message);
                    // }

            // $provider = ProviderDevice::where('provider_id',$provider_id)->with('provider')->first();

            // $provider = ProviderDevice::where('provider_id',$provider_id)->where('current','1')->with('provider')->orderBy('id','DESC')->first();

            // // dd($provider->token);

            // if($provider->token != ""){
                
            //     \Log::info('sendnig push for provider : '. $provider->provider->first_name);

            //  if($provider->type == 'ios'){

            //      \PushNotification::app('IOSProvider')
               //          ->to($provider->token)
               //          ->send($push_message); 

            //  }elseif($provider->type == 'android'){
                    
            //      \PushNotification::app('AndroidProvider')
               //          ->to($provider->token)
            //             ->send($push_message);
                        

            //  }
            // }


            $provider = ProviderDevice::where('provider_id',$provider_id)->with('provider')->first();           

            if($provider->token != ""){

                if($provider->type == 'ios'){

                    if(env('IOS_USER_ENV')=='development'){
                        $crt_user_path=app_path().'/apns/user/enterprise_user.pem';
                        $crt_provider_path=app_path().'/apns/user/enterprise_user.pem';
                        $dry_run = true;
                    }
                      else{
                         $crt_user_path=app_path().'/apns/user/enterprise_user.pem';
                        $crt_provider_path=app_path().'/apns/user/enterprise_user.pem';
                        $dry_run = false;
                    }

                   $push = new PushNotification('apn');
                   $push->setConfig([
                            'certificate' => $crt_provider_path,
                            'passPhrase' => env('IOS_PROVIDER_PUSH_PASS', 'apple'),
                            'dry_run' => $dry_run
                        ]);
                   $send=  $push->setMessage([
                            'aps' => [
                                'alert' => [
                                    'body' => $push_message
                                ],
                                'sound' => 'default',
                                'badge' => 1

                            ],
                            'extraPayLoad' => [
                                'custom' => $push_message
                            ]
                        ])
                        ->setDevicesToken($provider->token)->send();
                
                    
                    return $send;

                }elseif($provider->type == 'android'){
                    
                   $push = new PushNotification('fcm');
                   $send=  $push->setMessage(['message'=>$push_message])
                        ->setDevicesToken($provider->token)->send();
                    
                    return $send;
                }
            }

        } catch(Exception $e){
            return $e;
        }

    }

}

that is my code. line 402 is below

elseif($provider->type == 'android'){
                
               $push = new PushNotification('fcm');
               $send=  $push->setMessage(['message'=>$push_message])
                    ->setDevicesToken($provider->token)->send();
                
                return $send;
            }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/33KfmQD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire