csaba_szekely's avatar

Making a messaging module

Hi all!

I'm making a messaging module, something similar to what is beneath the videos here at laracasts. And I remember that I saw in some of the series how this one was made by Jeffrey. Can someone point me to the right direction, as of which of the series was that. I searched but I can't find the right one.

0 likes
3 replies
LaryAI's avatar
Level 58

The messaging module you're referring to is likely covered in the series that deals with real-time interactive features using technologies like Laravel Echo, Vue.js, and Pusher or Laravel Websockets. While I can't point you to the exact series without more context, I can suggest a few series that might include the concepts you're looking for:

  1. Real-Time Laravel with Socket.io: This series could potentially cover the creation of a real-time messaging system using Socket.io with Laravel.

  2. Build A Chatroom App with Laravel and Vue.js: This is a practical series that walks through the process of building a chatroom, which is similar to a messaging module.

  3. Laravel Echo Essentials: This series covers Laravel Echo, which is a tool for working with WebSockets in Laravel. It's essential for real-time broadcasting and could be used to build a messaging system.

  4. Let's Build A Forum with Laravel and TDD: While this series focuses on building a forum, it covers many concepts that could be applied to a messaging system, such as real-time updates and notifications.

Here's a basic example of how you might set up a simple messaging system using Laravel and Vue.js:

// routes/web.php
Route::get('/messages', 'MessageController@index');
Route::post('/messages', 'MessageController@store');
// MessageController.php
class MessageController extends Controller
{
    public function index()
    {
        $messages = Message::all();
        return response()->json($messages);
    }

    public function store(Request $request)
    {
        $message = Message::create($request->all());
        broadcast(new MessageSent($message))->toOthers();
        return response()->json($message);
    }
}
// MessageSent.php (event)
class MessageSent implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;

    public function __construct(Message $message)
    {
        $this->message = $message;
    }

    public function broadcastOn()
    {
        return new Channel('messages');
    }
}
// app.js (Vue.js component)
new Vue({
    el: '#app',
    data: {
        messages: []
    },
    created() {
        axios.get('/messages').then(response => {
            this.messages = response.data;
        });

        Echo.channel('messages')
            .listen('MessageSent', (e) => {
                this.messages.push(e.message);
            });
    }
});
<!-- Blade template -->
<div id="app">
    <ul>
        <li v-for="message in messages">@{{ message.body }}</li>
    </ul>
</div>

Remember to replace the placeholders with your actual data and logic. You'll also need to set up Laravel Echo with Pusher or Laravel Websockets, and make sure you have the necessary Vue.js components.

If you're looking for more detailed instructions, I recommend checking out the series mentioned above on Laracasts, as they provide step-by-step guidance on building real-time applications with Laravel and Vue.js.

shariff's avatar

@csaba_szekely I believe you are seeking this series: "Building Laracasts," created by Jeffrey https://laracasts.com/series/building-laracasts . The latest installment, initiated by Luke Downing, is titled "Build a Forum with Laravel." You can find it at this link: https://laracasts.com/series/build-a-forum-with-laravel.

Please or to participate in this conversation.