<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Rezaul H Reza</title>
    <description>The latest articles on Forem by Rezaul H Reza (@rezaulhreza).</description>
    <link>https://forem.com/rezaulhreza</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F999085%2F57ea77c3-a5fa-4f42-9768-6263b0a7e8f8.jpeg</url>
      <title>Forem: Rezaul H Reza</title>
      <link>https://forem.com/rezaulhreza</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/rezaulhreza"/>
    <language>en</language>
    <item>
      <title>Creating a Chart.js Component in Alpine.js and Livewire: A Step-by-Step Guide</title>
      <dc:creator>Rezaul H Reza</dc:creator>
      <pubDate>Fri, 30 Dec 2022 17:19:29 +0000</pubDate>
      <link>https://forem.com/rezaulhreza/creating-a-chartjs-component-in-alpinejs-and-livewire-a-step-by-step-guide-556k</link>
      <guid>https://forem.com/rezaulhreza/creating-a-chartjs-component-in-alpinejs-and-livewire-a-step-by-step-guide-556k</guid>
      <description>&lt;p&gt;In this tutorial, we will learn how to create a Chart.js component in Alpine.js, a lightweight JavaScript framework that allows you to bind dynamic data to HTML templates. We will use the code provided above as a starting point, but first, let's take a closer look at the different components and how they work together.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;x-data&lt;/code&gt; attribute:&lt;/p&gt;

&lt;p&gt;The x-data attribute is used to define the initial state of an Alpine component. In this case, we have defined a property called chart which is set to null. This will be used to store the Chart.js object that we will create later.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;x-init&lt;/code&gt; attribute:&lt;/p&gt;

&lt;p&gt;The&lt;code&gt;x-init&lt;/code&gt; attribute is used to execute JavaScript code when the component is initialized. This is where we will create the Chart.js object and configure it with the desired options.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;canvas&lt;/code&gt;element:&lt;/p&gt;

&lt;p&gt;The canvas element is used to render the chart. We have given it an id of &lt;code&gt;myChart&lt;/code&gt; so that we can easily reference it in our JavaScript code.&lt;/p&gt;

&lt;p&gt;The Chart.js library:&lt;/p&gt;

&lt;p&gt;Finally, we need to include the Chart.js library in our HTML file. This can be done by adding a script element that points to the Chart.js CDN.&lt;/p&gt;

&lt;p&gt;Now that we have an overview of the different components, let's see how they work together to create a Chart.js component in Alpine.js.&lt;/p&gt;

&lt;p&gt;Step 1:&lt;/p&gt;

&lt;p&gt;First, we need to define the &lt;code&gt;x-data&lt;/code&gt; attribute for our component. As mentioned earlier, this is where we will define the initial state of our component, which in this case is a property called chart set to null.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div x-data="{ chart: null }"&amp;gt; ... &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2:&lt;/p&gt;

&lt;p&gt;Next, we will use the &lt;code&gt;x-init&lt;/code&gt; attribute to execute some JavaScript code when the component is initialized. This is where we will create the Chart.js &lt;code&gt;object&lt;/code&gt;and configure it with the desired options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div x-data="{ chart: null }" 
x-init=" chart = new Chart(document.getElementById('myChart').getContext('2d'), 
{ type: 'line', data: { labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], 
datasets: [{ label: 'My First Dataset', data: [65, 59, 80, 81, 56, 55, 40],
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderColor: 'rgba(255, 99, 132, 1)', borderWidth: 1 }] },
 options: {} }); "&amp;gt; ... &amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we are using the Chart constructor function provided by the Chart.js library to create a new chart. We pass in the canvas element's 2D rendering context as the first argument, and an object containing the chart configuration options as the second argument.&lt;/p&gt;

&lt;p&gt;Step 3:&lt;/p&gt;

&lt;p&gt;Next, we will add the canvas element to our component. This is where the chart will be rendered.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div x-data="{ chart: null }" x-init="
  chart = new Chart(document.getElementById('myChart').getContext('2d'), {
    type: 'line',
    data: {
      labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
      datasets: [{
        label: 'My First Dataset',
        data: [65, 59, 80, 81, 56, 55, 40],
        backgroundColor: 'rgba(255, 99, 132, 0.2)',
        borderColor: 'rgba(255, 99, 132, 1)',
        borderWidth: 1
      }]
    },
    options: {}
  });
"&amp;gt;
  &amp;lt;h1&amp;gt;Dashboard&amp;lt;/h1&amp;gt;
  &amp;lt;hr&amp;gt;
  &amp;lt;canvas id="myChart" width="400" height="400"&amp;gt;&amp;lt;/canvas&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4:&lt;/p&gt;

&lt;p&gt;Finally, we need to include the Chart.js library in our HTML file . For the sake of this post, we will implement it by adding a script element that points to the Chart.js CDN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.min.js"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we refresh the page now we should be able to see something like this&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fehgok3olouav82buylx9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fehgok3olouav82buylx9.png" alt="Chart" width="527" height="502"&gt;&lt;/a&gt;﻿&lt;/p&gt;

&lt;p&gt;To implement the same thing and get the data from a livewire component, we can do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a livewire component.&lt;/li&gt;
&lt;li&gt;Define properties to entangle with alpine.js&lt;/li&gt;
&lt;li&gt;Copy and paste the above snippet into the component's view file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let us create a new livewire component.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:livewire LivewireComponent&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then update the component class with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

use Livewire\Component;

class LivewireComponent extends Component
{
    public $name = 'Revenue by month with Livewire';

    public $labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];

    public $dataPoint = [65, 59, 80, 81, 56, 55, 40];

    public function render()
    {
        return view('livewire-component');
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note that the above are dummy data. To get data from database, you have to make the changes on query for your specific needs.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once done, we have to update replace the labels and datasets. Let's do it now.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div x-data="{ chart: null }" x-init="
    chart = new Chart(document.getElementById('myChart').getContext('2d'), {
      type: 'line',
      data: {
        labels: $wire.labels,
        datasets: [{
          label: $wire.name,
          data: $wire.dataPoint,
          backgroundColor: 'rgba(255, 99, 132, 0.2)',
          borderColor: 'rgba(255, 99, 132, 1)',
          borderWidth: 1
        }]
      },
      options: {}
    });
  "&amp;gt;
    &amp;lt;canvas id="myChart" width="400" height="400"&amp;gt;&amp;lt;/canvas&amp;gt;
  &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxgdj8sa6hjlq9mtrdlud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxgdj8sa6hjlq9mtrdlud.png" alt="Chart with Livewire" width="523" height="499"&gt;&lt;/a&gt;&lt;br&gt;
﻿&lt;/p&gt;

&lt;p&gt;We can also change the type of chart we want. Simply change the value&lt;/p&gt;

&lt;p&gt;&lt;code&gt;type: 'line'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;to &lt;/p&gt;

&lt;p&gt;&lt;code&gt;type:'bar'&lt;/code&gt;&lt;br&gt;
or&lt;br&gt;
&lt;code&gt;type: 'pie'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We should then be able to display a pie or  a bar chart.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1efb4yny1rk5bwnqpnwv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1efb4yny1rk5bwnqpnwv.png" alt="Bar Chart" width="520" height="509"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try it on &lt;a href="https://laravelplayground.com/#/snippets/33b303c6-4f42-4872-8eff-9b05cf6df0f8" rel="noopener noreferrer"&gt;Laravel Playground&lt;/a&gt; !&lt;/p&gt;

&lt;p&gt;And that's it! You now have a Chart.js component in Alpine.js and/or Livewire that displays a line/bar/pie chart. You can customize the chart further by modifying the configuration options passed to the Chart constructor function. For more information on the different options available, you can refer to the Chart.js documentation.&lt;/p&gt;

&lt;p&gt;I also post awesome free and premium components and articles on my &lt;a href="https://rezaulhreza.co.uk/" rel="noopener noreferrer"&gt;website&lt;/a&gt;.  You can find some amazing content there. &lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

</description>
      <category>ai</category>
      <category>discuss</category>
      <category>news</category>
    </item>
    <item>
      <title>MessageBird Integration with Laravel</title>
      <dc:creator>Rezaul H Reza</dc:creator>
      <pubDate>Fri, 30 Dec 2022 14:06:26 +0000</pubDate>
      <link>https://forem.com/rezaulhreza/messagebird-integration-with-laravel-3f7n</link>
      <guid>https://forem.com/rezaulhreza/messagebird-integration-with-laravel-3f7n</guid>
      <description>&lt;p&gt;Welcome to our tutorial on integrating MessageBird with Laravel!&lt;/p&gt;

&lt;p&gt;In this tutorial, we will show you how to install the laravel-notification-channels/messagebird package and set up your environment variables. We will also demonstrate how to test the integration using the PHPUnit framework. &lt;/p&gt;

&lt;p&gt;Before we begin, it's important to note that you will need to have an account with MessageBird in order to use their SMS service. If you don't already have an account, you can Sign Up for one at their website.&lt;/p&gt;

&lt;p&gt;Now, let's get started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the Package
&lt;/h2&gt;

&lt;p&gt;The first step in integrating MessageBird with Laravel is to install the &lt;code&gt;laravel-notification-channels/messagebird package&lt;/code&gt;. This package provides a MessageBird channel for Laravel's notification system, allowing you to send SMS messages through MessageBird from your Laravel application.&lt;/p&gt;

&lt;p&gt;To install the package:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;composer require laravel-notification-channels/messagebird&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Setting Up Your Environment Variables&lt;/p&gt;

&lt;p&gt;Next, you'll need to set up your environment variables. The &lt;code&gt;laravel-notification-channels/messagebird&lt;/code&gt; package requires several environment variables in order to connect to the MessageBird API.&lt;/p&gt;

&lt;p&gt;First, you'll need to add your MessageBird API key to the &lt;code&gt;.env&lt;/code&gt;file. You can find your API key in the MessageBird dashboard under "API Access (REST)".&lt;/p&gt;

&lt;p&gt;&lt;code&gt;MESSAGEBIRD_API_KEY=your-api-key-here&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The final version of .env variables should look like this:&lt;/p&gt;

&lt;h1&gt;
  
  
  rest of the env variables.....
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Messagebird
&lt;/h1&gt;

&lt;p&gt;MESSAGEBIRD_ACCESS_KEY=api_key&lt;br&gt;
MESSAGEBIRD_ORIGINATOR=NameOrNumberMessageWillBeSentFrom&lt;br&gt;
MESSAGEBIRD_TEST_RECIPIENT=&lt;/p&gt;

&lt;p&gt;In our &lt;code&gt;services.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php


return [

//..........


'messagebird' =&amp;gt; [
        'access_key' =&amp;gt; env('MESSAGEBIRD_ACCESS_KEY'),
        'originator' =&amp;gt; env('MESSAGEBIRD_ORIGINATOR'),
    ],


];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implementing and Testing the Integration&lt;/p&gt;

&lt;p&gt;Now that you have the &lt;code&gt;laravel-notification-channels/messagebird package installed and your environment variables set up&lt;/code&gt;, it's time to implement and test the integration.&lt;/p&gt;

&lt;p&gt;Create a notification using&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan make:notification MessageCreated&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will now create a new notification class in the &lt;code&gt;app/notifications&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;The beauty of laravel notifications classes are it’s very easy to send notifications. &lt;/p&gt;

&lt;p&gt;The new notification class should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Notifications\Customers;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use NotificationChannels\Messagebird\MessagebirdChannel;
use NotificationChannels\Messagebird\MessagebirdMessage;

class MessageCreated extends Notification implements ShouldQueue
{
    use Queueable;

    public function via($notifiable)
    {
        return [MessagebirdChannel::class];
    }

    public function toMessagebird($notifiable)
    {
        $message = new MessagebirdMessage("Message Sent!");

        if (app()-&amp;gt;environment('local', 'testing')) {
            $message-&amp;gt;setRecipients([env('MESSAGEBIRD_TEST_RECIPIENT')]);
        }

        return $message;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Time to start integrating them in our application!&lt;/p&gt;

&lt;p&gt;For the sake of this example, we are using &lt;code&gt;Livewire&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We will create a component called &lt;code&gt;TestComponent&lt;/code&gt;.&lt;br&gt;
`&lt;br&gt;
&amp;lt;?php&lt;/p&gt;

&lt;p&gt;namespace App\Http\Livewire;&lt;/p&gt;

&lt;p&gt;use Livewire\Component;&lt;br&gt;
use Notification;//illuminate/facade&lt;br&gt;
use App\Models\Order;&lt;br&gt;
use App\Notifications\MessageCreated;&lt;/p&gt;

&lt;p&gt;class TestComponent extends Component&lt;br&gt;
{&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public $order;

public $orderId;

public $name;

public $qty;

public $note;

public $phoneNumber;


public function store()
{

    $this-&amp;gt;order = Order::updateOrCreate(['id' =&amp;gt; $this-&amp;gt;orderId], [
        'name' =&amp;gt; $this-&amp;gt;name,
        'qty' =&amp;gt; $this-&amp;gt;qty
        'note' =&amp;gt; $this-&amp;gt;note ?? '',
        'user_id' =&amp;gt;  auth()-&amp;gt;user()-&amp;gt;id,

    ]);

    // Notify the user
    $phone = optional($this-&amp;gt;phoneNumber ?? '';//phone number must be in international format e.g +4478.....
    if ($phone) {
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;//this line is responsible to send notification when this method is called.&lt;br&gt;
         Notification::route('messagebird', $phone)-&amp;gt;notify(new MessageCreated);&lt;br&gt;
        }&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;}


public function render()
{

    return view('livewire.test-component');
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;Let’s update our view file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
&amp;lt;div class="flex flex-col"&amp;gt;
    &amp;lt;label class="block font-bold mb-2 text-gray-700" for="name"&amp;gt;
        Name
    &amp;lt;/label&amp;gt;
    &amp;lt;input 
        class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500" 
        id="name"
        wire:model="name"
        type="text" 
        placeholder="Enter your name"
    &amp;gt;
    &amp;lt;label class="block font-bold mb-2 text-gray-700" for="qty"&amp;gt;
        Quantity
    &amp;lt;/label&amp;gt;
    &amp;lt;input 
        class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500" 
        id="qty"
        wire:model="qty"
        type="number" 
        placeholder="Enter the quantity"
    &amp;gt;
    &amp;lt;label class="block font-bold mb-2 text-gray-700" for="note"&amp;gt;
        Note
    &amp;lt;/label&amp;gt;
    &amp;lt;textarea
        class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500" 
        id="note"
        wire:model="note"
        placeholder="Enter a note"
    &amp;gt;&amp;lt;/textarea&amp;gt;
    &amp;lt;label class="block font-bold mb-2 text-gray-700" for="phoneNumber"&amp;gt;
        Phone number
    &amp;lt;/label&amp;gt;
    &amp;lt;input
        class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500" 
        id="phoneNumber"
        wire:model="phoneNumber"
        type="tel"
        placeholder="Enter your phone number"
    &amp;gt;
    &amp;lt;button
        class="bg-purple-500 hover:bg-purple-700 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline"
        wire:click="store"
    &amp;gt;
        Submit
    &amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have created the component, it’s time to test the integration.&lt;/p&gt;

&lt;p&gt;To do this, we'll use the PHPUnit.&lt;/p&gt;

&lt;p&gt;First, add the following line to your &lt;code&gt;phpunit.xml&lt;/code&gt; file:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;envname="MESSAGEBIRD_TEST_RECIPIENT"value="+447000000000" /&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will define a test recipient phone number that you can use in your tests. The reason we are including it here because we don’t want our production data to be in the test file.&lt;/p&gt;

&lt;p&gt;Next, in your test file, make sure to use the Notification::fake() method at the top of your test or in the setup method. This will prevent any real SMS messages from being sent during your tests.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;protected function setUp(): void&lt;br&gt;
{ &lt;br&gt;
  parent::setUp();&lt;br&gt;
 // Make sure we don't send real SMS texts&lt;br&gt;
  Notification::fake();&lt;br&gt;
 }&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After performing the action that should trigger an SMS message, you can use the &lt;code&gt;Notification::assertSentTo()&lt;/code&gt; method to perform an assertion. This method takes three arguments: the notifiable entity, the notification class, and a callback function that should return true if the assertion should pass.&lt;/p&gt;

&lt;p&gt;Here's an example of how you might use this method in a test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function test_order_notification_is_sent()
 {

   protected function setUp(): void
 {
     parent::setUp();

     // Make sure we don’t send real SMS texts
     Notification::fake();
 }

     Livewire::actingAs($user)
         -&amp;gt;test(TestComponent::class)

         -&amp;gt;set(‘property ’, ‘property value)

         -&amp;gt;call(‘method’);//method to call i.e ‘submit’

     Notification::assertSentTo(
         new AnonymousNotifiable(),
         MessageCreated::class,
         function ($notification, $channels, $notifiable) {
             return $notifiable-&amp;gt;routes[‘messagebird’] === ‘+447000000000’;
         }
     );
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, we need to change our &lt;code&gt;AppServiceProvider&lt;/code&gt;. The integration will not work if &lt;code&gt;guzzle&lt;/code&gt;cannot verify the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Providers;

use GuzzleHttp\Client;
use NotificationChannels\Messagebird\MessagebirdClient;
use NotificationChannels\Messagebird\MessagebirdChannel;
use NotificationChannels\Messagebird\Exceptions\InvalidConfiguration;



public function boot()
{
          // Override Messagebird service provider to instruct Guzzle not to verify their API SSL certificate
        $this-&amp;gt;app-&amp;gt;when(MessagebirdChannel::class)
            -&amp;gt;needs(MessagebirdClient::class)
           -&amp;gt;give(function () {
                $config = config('services.messagebird');

                if (is_null($config)) {
                    throw InvalidConfiguration::configurationNotSet();
               }

                return new MessagebirdClient(new Client(['verify' =&amp;gt; false]), $config['access_key']);
                });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the test and it should pass.&lt;br&gt;
&lt;code&gt;phpunit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's it! You should now have a working integration between MessageBird and Laravel, and you can send message to your customers or users very easily.&lt;/p&gt;

&lt;p&gt;If you have any questions or need further assistance, you can refer to the documentation for the laravel-notification-channels/messagebird package or the MessageBird documentation. You are also welcomed to leave a comment if you have any queries regarding the integration.&lt;/p&gt;

&lt;p&gt;I also post awesome free and premium components and articles on my &lt;a href="https://rezaulhreza.co.uk/"&gt;website&lt;/a&gt;.  You can find some amazing content there. &lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
