Build a Simple Chat Room App in React with Laravel Breeze and Twilio's Conversations API

I am a full-stack web developer that enjoys coding in Laravel and React.
Search for a command to run...

I am a full-stack web developer that enjoys coding in Laravel and React.
No comments yet. Be the first to comment.
Switching stacks

If you don't know what Twin Macro is, check it out! It's a great library that blends Tailwind CSS and Styled Component systems, like Emotion. I love using Twin because it lets me use Tailwind while separating my styling from my markup and methods. If...

Extending the Rule Object with a DateTime Trait

Using Custom Console Commands

Many developers know that full-stack apps with a Vue frontend can be quickly spun up with Laravel Jetstream. What many don’t know is that recently, the Laravel team made it easy to make an Inertia app with Laravel Breeze. In this article, we'll make a simple Discord-like app called Twilcord” that will let multiple users join a room via a phone number or username. Instead of the default Vue frontend, we’ll be using React.
The Gist:
$ npm install @inertiajs/inertia-react. Then we'll import it and redo our app.js file, like so:import {InertiaApp} from '@inertiajs/inertia-react'
import React from 'react'
import {render} from 'react-dom'
const app = document.getElementById('app')
render (
<InertiaApp
initialPage={JSON.parse(app.dataset.page)}
resolveComponent={name => import(`./Pages/${name}`).then(
module => module.default
)}
/>,
app
)
composer require twilio/sdk and ensure that we have our Twilio phone number, account SID, and auth token. We can get these from the Console.AppServiceProvider.<?php
namespace App\Providers;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\ServiceProvider;
use Inertia\Inertia;
class AppServiceProvider extends ServiceProvider
{
...
public function boot()
{
Inertia::share('flash', function(){
return [
'message' => Session::get('message')
];
});
}
}
// Fetch messages
async function getMessages(){
const response = await fetch(`/convo/${chat.sid}/messages`)
const json = await response.json()
if (json.messages.length > arrLength){
setMessages(json.messages)
setArrLength(json.messages.length)
}
}
// Fetch messages every three seconds and clean up once component unmounts
useEffect(() => {
const interval = setInterval(() => {
getMessages()
}, 3000)
return () => clearInterval(interval)
}, [])
This tutorial is just meant to show the basics of Laravel Breeze, Inertia, setting React up with Laravel and Inertia, and Twilio's Conversations API. A more detailed and real-world tutorial will be written up soon. But in the meantime, if you think you're up to it: