在Laravel for Twilio中找不到“Illuminate \ Foundation \ Exceptions \ Handler”类

时间:2016-09-08 12:31:52

标签: php api laravel sms twilio

我是Laravel和Twilio SMS API的新手。 我已下载并安装了laravel编辑器,并使用命令将PHP SDK添加到我的composer.json文件中,如twilio网站上所述:

composer require twilio/sdk

当我运行项目的主页时,我收到此错误:

Fatal error: Class 'Illuminate\Foundation\Exceptions\Handler' not found in C:\wamp64\www\server-notifications-laravel-master\app\Exceptions\Handler.php on line 16

这是什么意思?问题来自哪里?

<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Log;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Twilio\Rest\Client;
use Twilio\Exceptions\TwilioException;

class Handler extends ExceptionHandler
{
    protected $dontReport = [
        HttpException::class,
        ModelNotFoundException::class,
    ];


    public function report(Exception $e)
    {
        $this->_notifyThroughSms($e);
        return parent::report($e);
    }

    public function render($request, Exception $e)
    {
        if ($e instanceof ModelNotFoundException) {
            $e = new NotFoundHttpException($e->getMessage(), $e);
        }

        return parent::render($request, $e);
    }

    private function _notifyThroughSms($e)
    {
        foreach ($this->_notificationRecipients() as $recipient) {
            $this->_sendSms(
                $recipient->phone_number,
                '[This is a test] It appears the server' .
                ' is having issues. Exception: ' . $e->getMessage() .
                ' Go to http://newrelic.com for more details.'
            );
        }
    }

    private function _notificationRecipients()
    {
        try {
             $adminsFileContents = array("name" => "Shreyas", "phone_number" => "+919769990261");

            return json_decode($adminsFileContents);
        } catch (FileNotFoundException $e) {
            Log::error(
                'Could not find ' .
                $adminsFile .
                ' to notify admins through SMS'
            );
            return [];
        }
    }

    private function _sendSms($to, $message)
    {
        $accountSid = env('AC75b9e39594f4c8e18e52a8b94afb911b');
        $authToken = env('594463d16b96cf6bafc11778fce64d64');
        $twilioNumber = env('+12562740392');

        $client = new Client($accountSid, $authToken);

        try {
            $client->messages->create(
                $to,
                [
                    "body" => $message,
                    "from" => $twilioNumber
                    //   On US phone numbers, you could send an image as well!
                    //  'mediaUrl' => $imageUrl
                ]
            );
            Log::info('Message sent to ' . $twilioNumber);
        } catch (TwilioException $e) {
            Log::error(
                'Could not send SMS notification.' .
                ' Twilio replied with: ' . $e
            );
        }
    }
}

0 个答案:

没有答案