HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: //var/www/html/punjabcabs/app/Http/Controllers/SmsController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Provider;
use App\Smsnotification;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use App\Http\Controllers\Controller;
use Exception;

use Setting;
use Twilio;

class SmsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        try{
            $Providers = Provider::all();
            $smsdatas = Smsnotification::where('notification_type','sms')->where('member','driver')->orderBy('created_at' , 'desc')->get();
            return view('admin.pushmessage.index', compact('Providers','smsdatas'));
        }
        catch (Exception $e) {
             return back()->with('flash_error','Something Went Wrong!');
        }
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        try{
            $message = $request->push_content;
            $mobiles = array_unique($request->drivers);
            if(Setting::get('sms_enable', 0) == 1) {
                foreach ($mobiles as $mobile) {
                     try {
                         Twilio::message($mobile, $message);
                    } catch ( \Services_Twilio_RestException $e ) {
                         //return $e;  
                    }
                }

                $mobiles = implode(', ', $mobiles);
                Smsnotification::create([
                    'message' => $message,
                    'mobile_numbers' => $mobiles,
                    'member' =>'driver',
                    'notification_type' =>'sms'
                ]);
                return back()->with('flash_success', 'SMS Sent Successfully!');
            }else{
                return back()->with('flash_error','Sending SMS Not Enabled');
            }
        }
        catch (Exception $e) {
             return back()->with('flash_error','Something Went Wrong! (Check All Drivers Mobile Number with Country Code)');
        }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Request $request)
    {
        try{
            $checkboxes = $request->input('checkbox');
            $count = count($checkboxes);
            if($count == 0){
                return back()->with('flash_error', 'Please Select Row to Delete');
            }
            foreach($checkboxes as $id) {
                Smsnotification::where('id', $id)->delete();
            }
            return back()->with('flash_success', 'Deleted Successfully!');
        }
        catch (Exception $e) {
             return back()->with('flash_error','Something Went Wrong!');
        }
    }
}