Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ehabafia's avatar

Laravel make a call to a phone through Twilio

I am wondering if someone can help me here for a Twilio Call, here is the code:

$lead = Lead::findOrFail($request->id);
        $notification = NotificationSetting::find($request->prc);

        $response = new VoiceResponse();
        $response->play(url('storage/'.$notification->voice_call), ['loop' => 10]);

        $client = new Client(config('mtc.twilio.sid'), config('mtc.twilio.token'));

        $call = $client->account->calls
               ->create('+1'.$lead->phone, // to
                        config('mtc.twilio.from'), //from
                        ['twiml' => $response]
               );

The problem is when I call the code through ngrok it works fine, but when I using through forge.laravel.com, it doesn't. It calls my phone but it tells me that there is an error. While when I use my local, it works just fine.

Any idea why?

Thank you,

0 likes
5 replies
ajohnson6494's avatar

Check your config file on production and insure that you have your URL specified correctly. I am guessing that Twilio cannot access your audio file.

ehabafia's avatar

it says that it can't while the file is there I checked the URL and it's correct and everything seems to be correct. Not sure why.

ehabafia's avatar

The only difference I can see is that if I put the URL of the mp3 file of the local it plays it, while if I put the production URL it forces me to download it.

So, how can I make the file in the production to be played if I put the URL in the browser?

ajohnson6494's avatar

Can you see what $response is on production? Is the xml what you are expecting?

ehabafia's avatar
ehabafia
OP
Best Answer
Level 37

I got the problem, thank you for your support.

The problem was when I use the code:

 $request->file_name->store('notifications', 'public');

Laravel is considering that the file is not mp3, instead it's mpga, so it uploaded it as mpga.

I used instead:

$file = $request->file_name;
$file->move(public_path('storage/notification)', $filename);

it worked perfectly.

Please or to participate in this conversation.