<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mamoun K. Abu Salah on Medium]]></title>
        <description><![CDATA[Stories by Mamoun K. Abu Salah on Medium]]></description>
        <link>https://medium.com/@mamounkamal21_37463?source=rss-e72e9c8d8e1e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5N-X8ppGpL0afcRiZDmsJg.png</url>
            <title>Stories by Mamoun K. Abu Salah on Medium</title>
            <link>https://medium.com/@mamounkamal21_37463?source=rss-e72e9c8d8e1e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 08:14:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mamounkamal21_37463/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ZATCA E-Invoice Integration Guide — Part 2
 From Sandbox to Simulation & Production: Compliance…]]></title>
            <link>https://medium.com/@mamounkamal21_37463/zatca-e-invoice-integration-guide-part-2-from-sandbox-to-simulation-production-compliance-f7aa7194a75e?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7aa7194a75e</guid>
            <category><![CDATA[zakat]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[e-invoice-software]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[zatca]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Fri, 02 Jan 2026 12:29:54 GMT</pubDate>
            <atom:updated>2026-01-02T12:29:54.850Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Zatca with Laravel" src="https://cdn-images-1.medium.com/max/450/1*L5yazVir9-TgKpQt_v62jQ.png" /><figcaption>Zatca</figcaption></figure><h3><strong>ZATCA E-Invoice Integration Guide — Part 2</strong><br> <strong>From Sandbox to Simulation &amp; Production: Compliance, Certificates, and Real Invoice Reporting with Laravel</strong></h3><p><a href="https://medium.com/@mamounkamal21_37463/zatca-e-invoice-integration-guide-a-complete-e-invoicing-integration-journey-with-laravel-3860c56e6b33">In the first part of this guide</a>, we explained the fundamentals of integrating e-invoicing with ZATCA using Laravel, setting up the Sandbox environment, and understanding the structure of the invoice XML file.</p><p>In this part (Part 2), we will move step by step through the real journey that any actual e-invoice system goes through: “Transitioning from Sandbox to Simulation”.</p><h3>Overview of the Complete Journey (High-Level Flow)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3AwFbco6XXC8nevhWuIvcw.png" /><figcaption>Zatca High-Level Flow</figcaption></figure><p>Before diving into the technical details, let’s first look at the complete journey that we will cover in this guide. This flow represents the real-life process that any compliant e-invoicing system must go through when integrating with ZATCA:</p><ol><li><strong>CSR and Private Key Generation</strong><br> Generate the Certificate Signing Request (CSR) along with the private key that will be used to authenticate your system with ZATCA.</li><li><strong>Requesting the Compliance Certificate</strong><br> Submit the generated CSR to ZATCA to obtain the <strong>Compliance Certificate</strong>, which is required to validate your invoices during the compliance phase.</li><li><strong>Generating ZATCA Invoice XML</strong><br> Create invoice XML files that comply with ZATCA specifications.<br> Depending on the value of ZATCA_INVOICE_TYPE, the supported invoice types are:</li></ol><ul><li><strong>1100</strong> → Simplified and Standard invoices</li><li><strong>0100</strong> → Simplified invoices only</li><li><strong>1000</strong> → Standard invoices only</li></ul><p>In this guide, we will focus on <strong>Simplified invoices only</strong>.</p><p>4. <strong>Generating Credit and Debit Notes</strong></p><ul><li>If your system supports <strong>both Simplified and Standard invoices</strong>, you must generate <strong>Credit and Debit Notes for each type</strong>.</li><li>If your system supports <strong>Simplified invoices only</strong>, then you only need to generate <strong>Credit and Debit Notes for Simplified invoices</strong>.</li></ul><p>5.<strong> Signing Invoice XML Files</strong><br> Digitally sign all generated XML files, including:</p><ul><li>Simplified invoices</li><li>Credit notes</li><li>Debit notes</li></ul><p>6. <strong>Submitting Signed Invoices for Compliance</strong><br> Submit the signed XML files to ZATCA for compliance validation. This includes:</p><ul><li>Signed simplified invoices</li><li>Signed credit notes</li><li>Signed debit notes</li></ul><p>7. <strong>Requesting the Production Certificate</strong><br> After successfully passing the compliance phase, request the <strong>Production Certificate</strong>, which allows your system to operate in the live environment.</p><p>8. <strong>Reporting Real Invoices</strong><br> Once the Production Certificate is issued, you can start reporting real (production) invoices to ZATCA.</p><h3>Why Simulation?</h3><p>The Simulation environment represents a setup that is much closer to real production usage. It is designed to ensure that your system is fully compliant before going live.</p><p>It requires:</p><ul><li>An <strong>OTP</strong> generated from the ZATCA portal</li><li>A <strong>real Compliance Certificate</strong></li><li>Almost the <strong>same rules as the Production environment</strong>, but without any real financial or legal impact</li></ul><p><strong>Obtaining the OTP</strong></p><p>To complete the integration process, you need to obtain an OTP by following these steps:</p><ol><li>Log in to the <strong>ZATCA Portal</strong>.</li><li>Navigate to the <strong>Simulation Environment</strong>.</li><li>Generate and retrieve the <strong>OTP</strong>, which will be used to authenticate your system during the onboarding process.</li></ol><h4>Practical Steps and Required Changes (Based on Part 1)</h4><p>After finishing the Sandbox setup, we need to apply a few configuration changes and run specific commands to move into the <strong>Simulation environment</strong>.</p><p><strong>1. Update Environment Variables</strong></p><p>First, update your .env file with the following values:</p><ul><li><strong>Set the OTP received from the ZATCA portal</strong></li><li>ZATCA_OTP=XXXXXXXX</li><li><strong>Confirm the invoice type is Simplified only</strong></li><li>ZATCA_INVOICE_TYPE=0100</li><li><strong>Switch the environment to Simulation</strong></li><li>ZATCA_ENVIRONMENT=simulation</li></ul><p>2. This command generates a <strong>new private key and CSR</strong> specifically for the <strong>Simulation environment</strong>.</p><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use Illuminate\Console\Command;<br>use Saleh7\Zatca\CertificateBuilder;<br>use Saleh7\Zatca\Exceptions\CertificateBuilderException;<br><br>class ZatcaGenerateCsr extends Command<br>{<br>    protected $signature = &#39;zatca:generate-csr&#39;;<br>    protected $description = &#39;Generate ZATCA CSR (Certificate Signing Request) and Private Key&#39;;<br><br>    public function handle()<br>    {<br>        $this-&gt;info(&#39;Starting ZATCA CSR and Private Key generation...&#39;);<br><br>        try {<br>            $builder = (new CertificateBuilder())<br>                -&gt;setOrganizationIdentifier(config(&#39;zatca.organization.identifier&#39;)) <br>                // Organization Identifier must be 15 digits, starting and ending with 3<br><br>                -&gt;setSerialNumber(<br>                    config(&#39;zatca.device.solution_name&#39;),<br>                    config(&#39;zatca.device.model&#39;),<br>                    config(&#39;zatca.device.serial_number&#39;)<br>                )<br>                // Each device must have a unique serial number<br><br>                -&gt;setCommonName(config(&#39;zatca.organization.name&#39;))<br>                -&gt;setCountryName(config(&#39;zatca.organization.country_code&#39;)) // Two characters only<br>                -&gt;setOrganizationName(config(&#39;zatca.organization.name&#39;))<br>                -&gt;setOrganizationalUnitName(config(&#39;zatca.organization.name&#39;))<br>                -&gt;setAddress(config(&#39;zatca.organization.address&#39;)) // Example: Riyadh, 1234 Street<br>                -&gt;setInvoiceType(config(&#39;zatca.invoice_type&#39;)) <br>                // Four digits: Standard, Simplified, Future, Future<br><br>                -&gt;setProduction(config(&#39;zatca.is_production&#39;)) // false for Simulation<br>                -&gt;setBusinessCategory(config(&#39;zatca.organization.business_category&#39;))<br>                -&gt;generateAndSave(<br>                    &#39;storage/zatca/output/certificate.csr&#39;,<br>                    &#39;storage/zatca/output/private.pem&#39;<br>                );<br><br>            echo &quot;Certificate and private key saved.\n&quot;;<br>            return Command::SUCCESS;<br><br>        } catch (CertificateBuilderException $e) {<br>            echo &quot;Error: &quot; . $e-&gt;getMessage() . &quot;\n&quot;;<br>            return Command::FAILURE;<br>        }<br>    }<br>}</pre><pre>php artisan zatca:generate-csr</pre><p>At this stage, you should have:</p><ul><li>certificate.csr</li><li>private.pem</li></ul><p>Saved under: \storage/zatca/output/</p><p>3. <strong>Request the Compliance Certificate (Simulation)</strong></p><p>Run the following command <strong>after confirming the OTP is set correctly</strong>:</p><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use Illuminate\Console\Command;<br>use GuzzleHttp\Client;<br>use Sevaske\ZatcaApi\Api;<br>use Sevaske\ZatcaApi\Exceptions\ZatcaException;<br><br>class ZatcaRequestComplianceCertificate extends Command<br>{<br>    protected $signature = &#39;zatca:request-compliance-certificate {otp? : The OTP received from ZATCA}&#39;;<br>    protected $description = &#39;Request Compliance Certificate from ZATCA using the generated CSR&#39;;<br><br>    public function handle()<br>    {<br>        $api = new Api(config(&#39;zatca.environment&#39;), new Client);<br>        $certificatePath = storage_path(&#39;zatca/output/certificate.csr&#39;);<br>        $csr = file_get_contents($certificatePath);<br><br>        try {<br>            echo &quot;CSR loaded successfully.\n&quot;;<br>            echo &quot;Requesting compliance certificate from ZATCA...\n&quot;;<br><br>            $response = $api-&gt;complianceCertificate($csr, config(&#39;zatca.otp&#39;));<br><br>            $credentials = [<br>                &#39;requestId&#39;   =&gt; $response-&gt;requestId(),<br>                &#39;certificate&#39; =&gt; $response-&gt;certificate(),<br>                &#39;secret&#39;      =&gt; $response-&gt;secret(),<br>            ];<br><br>            print_r($credentials);<br><br>            // Save compliance certificate data<br>            $outputFile = storage_path(&#39;zatca/output/ZATCA_certificate_data.json&#39;);<br>            file_put_contents($outputFile, json_encode($credentials, JSON_PRETTY_PRINT));<br><br>            echo &quot;\nCertificate data saved to {$outputFile}\n&quot;;<br>            return Command::SUCCESS;<br><br>        } catch (ZatcaException $e) {<br>            echo &quot;API Error: &quot; . $e-&gt;getMessage() . &quot;\n&quot;;<br>            print_r($e-&gt;context());<br>            return Command::FAILURE;<br><br>        } catch (\Exception $e) {<br>            echo &quot;Error: &quot; . $e-&gt;getMessage();<br>            return Command::FAILURE;<br>        }<br>    }<br>}</pre><pre>php artisan zatca:request-compliance-certificate</pre><p>After obtaining the <strong>Compliance Certificate</strong>, the next steps complete the Simulation journey and prepare your system for real invoice reporting.</p><p><strong>1. Generate Invoices and Notes</strong></p><p>Start by generating the following <strong>Simplified invoice documents</strong>:</p><ul><li><strong>Simplified Invoice</strong></li><li><strong>Credit Note</strong> for the simplified invoice</li><li><strong>Debit Note</strong> for the simplified invoice</li></ul><p>These documents are required during the <strong>compliance phase</strong> to prove that your system can correctly handle all supported invoice scenarios.</p><p>2. <strong>Sign Invoices Using the Compliance Certificate</strong></p><p>Next, digitally sign all generated XML files using the <strong>Compliance Certificate</strong>, including:</p><ul><li>The simplified invoice</li><li>The credit note</li><li>The debit note</li></ul><p>Signing ensures the integrity and authenticity of the invoices before submission to ZATCA.</p><p>3. <strong>Submit Invoices for Compliance Validation</strong></p><p>Submit the <strong>three signed invoices</strong> to ZATCA for compliance validation:</p><ul><li>Signed simplified invoice</li><li>Signed credit note</li><li>Signed debit note</li></ul><p>Once all submissions are accepted successfully, your system is considered <strong>compliance-approved</strong> in the Simulation environment.</p><p>4. <strong>Request the Production Certificate</strong></p><p>After passing compliance validation, request the <strong>Production Certificate</strong>.</p><p>Even though this is called a “Production” certificate, it will still be tied to the <strong>Simulation environment</strong> at this stage and will be used only for simulation reporting.</p><p><strong>5. Reporting Invoices in Simulation</strong></p><p>Once the Production Certificate is issued, your system is ready to <strong>report real-like invoices</strong> in the Simulation environment.</p><p>Important notes:</p><ul><li>You will report <strong>Simplified invoices only</strong></li><li>There is <strong>no need to report Credit or Debit Notes</strong> in the normal reporting flow</li><li>Credit and Debit Notes are only required for <strong>compliance testing</strong></li><li>If your product does <strong>not support discounts, additional fees, or adjustments</strong>, you will not need to generate credit or debit notes in the real reporting flow</li></ul><h3>Summary</h3><ul><li>Move from <strong>Sandbox</strong> to the <strong>Simulation environment</strong></li><li>Update environment variables (OTP, invoice type, environment)</li><li>Generate <strong>CSR and private key</strong> for Simulation</li><li>Request and obtain the <strong>Compliance Certificate</strong></li><li>Generate a <strong>Simplified invoice</strong> along with its <strong>Credit and Debit Notes</strong></li><li><strong>Sign</strong> all invoices using the Compliance Certificate</li><li>Submit the signed invoices for <strong>Compliance validation</strong></li><li>After successful validation, request the <strong>Production Certificate</strong></li><li>Use this certificate in the <strong>Simulation environment</strong> to <strong>report Simplified invoices only</strong></li><li>Credit and Debit Notes are required <strong>only for compliance testing</strong>, not for normal reporting if no discounts or fees are applied</li></ul><p>At this stage, the system is fully compliant in Simulation and ready for real-world reporting when moving to Production.</p><p>If you need any help, practical implementation guidance, access to the full source code, or would like to get a free consultation, feel free to reach out to me.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7aa7194a75e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ZATCA E-Invoice Integration Guide: A Complete E-Invoicing Integration Journey with Laravel]]></title>
            <link>https://medium.com/@mamounkamal21_37463/zatca-e-invoice-integration-guide-a-complete-e-invoicing-integration-journey-with-laravel-3860c56e6b33?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3860c56e6b33</guid>
            <category><![CDATA[zatca-compliant-invoicing]]></category>
            <category><![CDATA[zatca]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[saudi-arabia]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Fri, 17 Oct 2025 13:08:11 GMT</pubDate>
            <atom:updated>2025-10-17T13:08:11.812Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lBOhWXgW83DGznm-VnNQ6A.png" /><figcaption>Zatca with Laravel</figcaption></figure><p>In 2025, Saudi Arabia’s Zakat, Tax and Customs Authority (ZATCA) mandated e-invoicing for all businesses. As a developer working on an auction platform, I needed to implement ZATCA compliance integration from scratch for our Laravel-based platform.</p><p>This is the complete story of my journey — from zero knowledge to a fully working ZATCA integration, including every obstacle I encountered and how I overcame them.</p><p>The <strong>Zakat, Tax and Customs Authority (ZATCA)</strong> is a government agency under the <strong>Ministry of Finance</strong> in Saudi Arabia, responsible for the <strong>assessment and collection of taxes and zakat</strong> — a form of obligatory almsgiving in Islam. ZATCA requires Saudi and GCC-based companies to pay zakat as part of their financial obligations.</p><p>ZATCA operates across three main environments: <strong>Sandbox</strong>, <strong>Simulation</strong>, and <strong>Production</strong> — each serving a specific role in testing, validating, and deploying e-invoicing solutions. The authority defines different types of invoices, such as <strong>Standard</strong> and <strong>Simplified</strong> invoices.</p><p>In our current implementation, we focused on the <strong>Simplified Tax Invoice</strong>, which is typically issued by a business to a consumer (<strong>B2C</strong>) and includes all the required elements defined by ZATCA for simplified invoices.</p><p>And this is the format and structure of the invoice that must be sent to the customer:</p><p><a href="https://zatca.gov.sa/en/E-Invoicing/Introduction/Pages/What-is-e-invoicing.aspx">What is E-invoicing?</a></p><p><em>If you’d like to consult about the matter, feel free to contact me — I can help you, inshallah.</em></p><h4>Key Features of <a href="https://github.com/sevaske/php-zatca-xml">php-zatca-xml</a></h4><ol><li><strong>ZATCA Compliance</strong><br> The library helps you generate e-invoices that are compliant with ZATCA (Saudi Arabia’s tax authority) requirements. <a href="https://github.com/sevaske/php-zatca-xml">GitHub</a></li><li><strong>Invoice &amp; Note Generation (XML)</strong><br> You can create different types of documents (e.g. simplified invoice, standard invoice, credit notes, debit notes) in XML format. <a href="https://github.com/sevaske/php-zatca-xml">GitHub</a></li><li><strong>Digital Signing of Invoices</strong><br> The library supports signing invoices digitally to ensure they meet legal and security requirements. <a href="https://github.com/sevaske/php-zatca-xml">GitHub</a></li><li><strong>QR Code Generation</strong><br> It can automatically generate QR codes for invoices. <a href="https://github.com/sevaske/php-zatca-xml">GitHub</a></li><li><strong>Submission to ZATCA API</strong><br> Direct submission of signed invoices to the ZATCA servers (for validation or clearance) is supported.</li></ol><h4>🛠 Installation</h4><pre>composer require sevaske/php-zatca-xml</pre><p><strong>and also If you don’t already have an HTTP client:</strong></p><pre>composer require guzzlehttp/guzzle</pre><p><em>Create a new file at </em><em>config/zatca.php to store all your ZATCA settings (like credentials, environment, and certificate paths).</em></p><pre>&lt;?php<br><br>return [<br><br>    /*<br>    |--------------------------------------------------------------------------<br>    | ZATCA Environment<br>    |--------------------------------------------------------------------------<br>    |<br>    | The environment for ZATCA integration. Options: &#39;sandbox&#39;, &#39;production&#39;<br>    |<br>    */<br><br>    &#39;environment&#39; =&gt; env(&#39;ZATCA_ENVIRONMENT&#39;, &#39;sandbox&#39;),<br><br>    /*<br>    |--------------------------------------------------------------------------<br>    | Organization Information<br>    |--------------------------------------------------------------------------<br>    |<br>    | Your organization details as registered with ZATCA<br>    |<br>    */<br><br>    &#39;organization&#39; =&gt; [<br>        &#39;identifier&#39; =&gt; env(&#39;ZATCA_ORGANIZATION_IDENTIFIER&#39;, &#39;15 digits&#39;),<br>        &#39;name&#39; =&gt; env(&#39;ZATCA_ORGANIZATION_NAME&#39;, &#39;Company Name&#39;),<br>        &#39;unit&#39; =&gt; env(&#39;ZATCA_ORGANIZATION_UNIT&#39;, &#39;Auction System&#39;),<br>        &#39;common_name&#39; =&gt; env(&#39;ZATCA_COMMON_NAME&#39;, &#39;Auction System&#39;),<br>        &#39;country_code&#39; =&gt; env(&#39;ZATCA_COUNTRY_CODE&#39;, &#39;SA&#39;),<br>        &#39;address&#39; =&gt; env(&#39;ZATCA_ADDRESS&#39;, &#39;Riyadh King Fahd Road&#39;),<br>        &#39;business_category&#39; =&gt; env(&#39;ZATCA_BUSINESS_CATEGORY&#39;, &#39;Online Auction and E-Commerce Services&#39;),<br>        &#39;building_number&#39; =&gt; env(&#39;ZATCA_BUILDING_NUMBER&#39;, &#39;8008&#39;),<br>        &#39;city_subdivision_name&#39; =&gt; env(&#39;ZATCA_CITY_SUBDIVISION_NAME&#39;, &#39;Al Olaya&#39;),<br>        &#39;city&#39; =&gt; env(&#39;ZATCA_CITY&#39;, &#39;Riyadh&#39;),<br>        &#39;postal_code&#39; =&gt; env(&#39;ZATCA_POSTAL_CODE&#39;, &#39;12345&#39;),<br>        &#39;registration_number&#39; =&gt; env(&#39;ZATCA_REGISTRATION_NUMBER&#39;, &#39;10 digits&#39;),<br>    ],<br><br>    /*<br>    |--------------------------------------------------------------------------<br>    | Device/Solution Information<br>    |--------------------------------------------------------------------------<br>    |<br>    | Information about your solution/device<br>    |<br>    */<br><br>    &#39;device&#39; =&gt; [<br>        &#39;solution_name&#39; =&gt; env(&#39;ZATCA_SOLUTION_NAME&#39;, &#39;Auction System&#39;),<br>        &#39;model&#39; =&gt; env(&#39;ZATCA_SOLUTION_MODEL&#39;, &#39;v1.0&#39;),<br>        &#39;serial_number&#39; =&gt; env(&#39;ZATCA_DEVICE_SERIAL_NUMBER&#39;, &#39;serial number here&#39;),<br>    ],<br><br>    /*<br>    |--------------------------------------------------------------------------<br>    | Helper Methods<br>    |--------------------------------------------------------------------------<br>    */<br><br>    &#39;is_production&#39; =&gt; env(&#39;ZATCA_ENVIRONMENT&#39;, &#39;sandbox&#39;) === &#39;production&#39;,<br>    &#39;currency&#39; =&gt; env(&#39;ZATCA_CURRENCY&#39;, &#39;SAR&#39;),<br>];</pre><h4>Here’s the super-simple as commands in Laravel for generating, signing and submit ZATCA invoice, step-by-step:</h4><p><strong>📜 1. Generating a Compliance Certificate</strong></p><p>First, generate a certificate signing request (CSR) and private key</p><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use Illuminate\Console\Command;<br>use Saleh7\Zatca\CertificateBuilder;<br>use Saleh7\Zatca\Exceptions\CertificateBuilderException;<br><br>class ZatcaGenerateCsr extends Command<br>{<br>    /**<br>     * The name and signature of the console command.<br>     *<br>     * @var string<br>     */<br>    protected $signature = &#39;zatca:generate-csr&#39;;<br><br>    /**<br>     * The console command description.<br>     *<br>     * @var string<br>     */<br>    protected $description = &#39;Generate ZATCA CSR (Certificate Signing Request) and Private Key&#39;;<br><br>    /**<br>     * Execute the console command.<br>     */<br>    public function handle()<br>    {<br>        $this-&gt;info(&#39;Starting ZATCA CSR and Private Key generation...&#39;);<br><br>        try {<br>            $builder = (new CertificateBuilder())<br>                -&gt;setOrganizationIdentifier(config(&#39;zatca.organization.identifier&#39;)) // The Organization Identifier must be 15 digits, starting and ending with 3<br>                // string $solutionName .. The solution provider name<br>                // string $model .. The model of the unit the stamp is being generated for<br>                // string $serialNumber .. # If you have multiple devices each should have a unique serial number<br>                -&gt;setSerialNumber(config(&#39;zatca.device.solution_name&#39;), config(&#39;zatca.device.model&#39;), config(&#39;zatca.device.serial_number&#39;))<br>                -&gt;setCommonName(config(&#39;zatca.organization.name&#39;)) // The common name to be used in the certificate<br>                -&gt;setCountryName(config(&#39;zatca.organization.country_code&#39;)) // The Country name must be Two chars only<br>                -&gt;setOrganizationName(config(&#39;zatca.organization.name&#39;)) // The name of your organization<br>                -&gt;setOrganizationalUnitName(config(&#39;zatca.organization.name&#39;)) // A subunit in your organization<br>                -&gt;setAddress(config(&#39;zatca.organization.address&#39;)) // like Riyadh 1234 Street <br>                -&gt;setInvoiceType(config(&#39;zatca.invoice_type&#39;)) // # Four digits, each digit acting as a bool. The order is as follows: Standard Invoice, Simplified, future use, future use <br>                -&gt;setProduction(config(&#39;zatca.is_production&#39;)) // true = Production |  false = Testing<br>                -&gt;setBusinessCategory(config(&#39;zatca.organization.business_category&#39;)) // Your business category like food, real estate, etc<br>               -&gt;generateAndSave(&#39;storage/zatca/output/certificate.csr&#39;, &#39;storage/zatca/output/private.pem&#39;);<br>            <br>            echo &quot;Certificate and private key saved.\n&quot;;<br>          <br>            <br>            return Command::SUCCESS;<br>            <br>        } catch (CertificateBuilderException $e) {<br>            echo &quot;Error: &quot; . $e-&gt;getMessage() . &quot;\n&quot;;<br>            return Command::FAILURE;<br>        }<br>    }<br>}</pre><p><em>run the following command to generate zatca/output/certification.csr and zatca/output/private.pem and save it in storage:</em></p><pre>php artisan zatca:generate-csr </pre><p><strong>🔐 2. Requesting a Compliance Certificate from ZATCA</strong></p><p>Once the CSR is generated, you need to request a compliance certificate from ZATCA’s API.</p><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use Illuminate\Console\Command;<br>use GuzzleHttp\Client;<br>use Sevaske\ZatcaApi\Api;<br>use Sevaske\ZatcaApi\Exceptions\ZatcaException;<br><br>class ZatcaRequestComplianceCertificate extends Command<br>{<br>    /**<br>     * The name and signature of the console command.<br>     *<br>     * @var string<br>     */<br>    protected $signature = &#39;zatca:request-compliance-certificate {otp? : The OTP received from ZATCA}&#39;;<br><br>    /**<br>     * The console command description.<br>     *<br>     * @var string<br>     */<br>    protected $description = &#39;Request Compliance Certificate from ZATCA using the generated CSR&#39;;<br><br>    /**<br>     * Execute the console command.<br>     */<br>    public function handle()<br>    {<br>        $api = new Api(config(&#39;zatca.environment&#39;), new Client);<br>        $certificatePath = storage_path(&#39;zatca/output/certificate.csr&#39;);<br>        $csr = file_get_contents($certificatePath);<br>        <br>        try {<br>            echo &quot;CSR loaded successfully.\n&quot;;<br>            echo &quot;Requesting compliance certificate from ZATCA...\n&quot;;<br>            <br>            // Request the compliance certificate from ZATCA<br>            /* the second parameter as otp and in sandbox zatca env <br>             you can use any otp */<br>            $response = $api-&gt;complianceCertificate($csr, &#39;123123&#39;);<br>            $credentials = [<br>                &#39;requestId&#39; =&gt; $response-&gt;requestId(),<br>                &#39;certificate&#39; =&gt; $response-&gt;certificate(),<br>                &#39;secret&#39; =&gt; $response-&gt;secret(),<br>            ];<br>            <br>            print_r($credentials);<br><br>            // Save file output/ZATCA_certificate_data.json<br>            $outputFile = storage_path(&#39;zatca/output/ZATCA_certificate_data.json&#39;);<br>            file_put_contents($outputFile, json_encode($credentials, JSON_PRETTY_PRINT));<br><br>            echo &quot;\nCertificate data saved to {$outputFile}\n&quot;;<br>            <br>            return Command::SUCCESS;<br>            <br>        } catch (ZatcaException $e) {<br>            echo &quot;API Error: &quot; . $e-&gt;getMessage() . &quot;\n&quot;;<br>            print_r($e-&gt;context());<br>            return Command::FAILURE;<br>        } catch (\Exception $e) {<br>            echo &quot;Error: &quot; . $e-&gt;getMessage();<br>            return Command::FAILURE;<br>        }<br>    }<br>}<br><br></pre><p><em>run the following command to json certification file and save it in storage:</em></p><pre>php artisan zatca:request-compliance-certificate  </pre><p><em>You only need to run these setup commands and generate the required files </em><strong><em>once</em></strong><em> for the same environment (e.g., </em><em>&quot;sandbox&quot;). After that, you can </em><strong><em>reuse the same configuration and generated files</em></strong><em> in all the following steps.</em></p><p>These next steps as commands but you can implement it as service or as you like design code pattern and this is as example simplified invoice with dump data as the following:</p><p><strong>🧾3. Generating an Invoice XML</strong></p><p>Now that we have the compliance certificate, we can generate a ZATCA-compliant e-invoice in XML format. <br><em>and you can implement and use another way to build invoice as json and use mapper </em><a href="https://github.com/sevaske/php-zatca-xml?tab=readme-ov-file#-3-generating-and-signing-an-invoice-xml"><em>example</em></a></p><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use Illuminate\Console\Command;<br>use Saleh7\Zatca\{<br>    SignatureInformation, UBLDocumentSignatures, ExtensionContent, UBLExtension, UBLExtensions,<br>    Signature, InvoiceType, AdditionalDocumentReference, TaxScheme, PartyTaxScheme, Address,<br>    LegalEntity, Delivery, Party, PaymentMeans, TaxCategory, AllowanceCharge, TaxSubTotal,<br>    TaxTotal, LegalMonetaryTotal, ClassifiedTaxCategory, Item, Price, InvoiceLine,<br>    GeneratorInvoice, Invoice, UnitCode, Attachment<br>};<br>use DateTime;<br>use Illuminate\Support\Str;<br>use DateTimeZone;<br><br>class ZatcaGenerateInvoice extends Command<br>{<br>    protected $signature = &#39;zatca:generate-invoice&#39;;<br>    protected $description = &#39;Generate a ZATCA-compliant Simplified Invoice (XML)&#39;;<br><br>    public function handle()<br>    {<br>        try {<br>            $issueDate = now()-&gt;utc();<br>            $uuid = Str::uuid();<br>           <br><br>            // === 1. UBL Signature Extensions ===<br>            $signatureInfo = (new SignatureInformation)<br>                -&gt;setReferencedSignatureID(&quot;urn:oasis:names:specification:ubl:signature:Invoice&quot;)<br>                -&gt;setID(&#39;urn:oasis:names:specification:ubl:signature:1&#39;);<br><br>            $ublDocSignatures = (new UBLDocumentSignatures)<br>                -&gt;setSignatureInformation($signatureInfo);<br><br>            $extensionContent = (new ExtensionContent)<br>                -&gt;setUBLDocumentSignatures($ublDocSignatures);<br><br>            $ublExtension = (new UBLExtension)<br>                -&gt;setExtensionURI(&#39;urn:oasis:names:specification:ubl:dsig:enveloped:xades&#39;)<br>                -&gt;setExtensionContent($extensionContent);<br><br>            $ublExtensions = (new UBLExtensions)<br>                -&gt;setUBLExtensions([$ublExtension]);<br><br>            // === 2. Signature Section ===<br>            $signature = (new Signature)<br>                -&gt;setId(&quot;urn:oasis:names:specification:ubl:signature:Invoice&quot;)<br>                -&gt;setSignatureMethod(&quot;urn:oasis:names:specification:ubl:dsig:enveloped:xades&quot;);<br><br>            // === 3. Invoice Type ===<br>            $invoiceType = (new InvoiceType())<br>                -&gt;setInvoice(&#39;simplified&#39;)<br>                -&gt;setInvoiceType(&#39;invoice&#39;)<br>                -&gt;setIsThirdParty(false);<br><br>            // === 4. Attachments ===<br>            $attachment = (new Attachment())<br>                -&gt;setBase64Content(&#39;NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==&#39;, &#39;base64&#39;, &#39;text/plain&#39;);<br><br>            // === 5. Additional Document References ===<br>            $additionalDocs = [<br>                (new AdditionalDocumentReference())-&gt;setId(&#39;ICV&#39;)-&gt;setUUID(&quot;10&quot;),<br>                (new AdditionalDocumentReference())-&gt;setId(&#39;PIH&#39;)-&gt;setAttachment($attachment),<br>                (new AdditionalDocumentReference())-&gt;setId(&#39;QR&#39;),<br>            ];<br><br>            // === 6. Supplier / Customer Info ===<br>            $taxScheme = (new TaxScheme())-&gt;setId(&quot;VAT&quot;);<br><br>            $partyTaxSchemeSupplier = (new PartyTaxScheme())<br>                -&gt;setTaxScheme($taxScheme)<br>                -&gt;setCompanyId(&#39;15 digits and start with 3&#39;);<br><br>            $partyTaxSchemeCustomer = (new PartyTaxScheme())<br>                -&gt;setTaxScheme($taxScheme);<br><br>            $addressSupplier = (new Address())<br>                -&gt;setStreetName(&#39;Riyadh King Fahd Road&#39;)<br>                -&gt;setBuildingNumber(&quot;8008&quot;)<br>                -&gt;setCitySubdivisionName(&#39;Al Olaya&#39;)<br>                -&gt;setCityName(&#39;Riyadh&#39;)<br>                -&gt;setPostalZone(&#39;12345&#39;)<br>                -&gt;setCountry(&#39;SA&#39;);<br><br>            // no proplem if customer not have adderess <br>            $addressCustomer = (new Address())<br>                -&gt;setStreetName(&#39;Salah Al-Din&#39;)<br>                -&gt;setBuildingNumber(&quot;1111&quot;)<br>                -&gt;setCitySubdivisionName(&#39;Al-Murooj&#39;)<br>                -&gt;setCityName(&#39;Riyadh&#39;)<br>                -&gt;setPostalZone(&#39;12222&#39;)<br>                -&gt;setCountry(&#39;SA&#39;);<br><br>            $legalEntitySupplier = (new LegalEntity())-&gt;setRegistrationName(&#39;Name Company&#39;);<br>            $legalEntityCustomer = (new LegalEntity())-&gt;setRegistrationName(&#39;Fatoora Samples&#39;);<br><br>            $supplierCompany = (new Party())<br>                -&gt;setPartyIdentification(&quot;10 digits&quot;) <br>                -&gt;setPartyIdentificationId(&quot;CRN&quot;)<br>                -&gt;setLegalEntity($legalEntitySupplier)<br>                -&gt;setPartyTaxScheme($partyTaxSchemeSupplier)<br>                -&gt;setPostalAddress($addressSupplier);<br><br>            $supplierCustomer = (new Party())<br>                -&gt;setPartyIdentification(&quot;10 digits&quot;) // 10 digits (NAT)<br>                -&gt;setPartyIdentificationId(&quot;NAT&quot;)<br>                -&gt;setLegalEntity($legalEntityCustomer)<br>                -&gt;setPartyTaxScheme($partyTaxSchemeCustomer)<br>                -&gt;setPostalAddress($addressCustomer);<br><br>            // === 7. Delivery / Payment ===<br>            $delivery = (new Delivery())-&gt;setActualDeliveryDate($issueDate-&gt;format(&#39;Y-m-d&#39;));<br>            $paymentMeans = (new PaymentMeans())-&gt;setPaymentMeansCode(&quot;10&quot;);<br><br>            // === 8. Tax Structure ===<br>            $taxCategory = (new TaxCategory())<br>                -&gt;setPercent(15)<br>                -&gt;setTaxScheme($taxScheme);<br><br>            $taxSubTotal = (new TaxSubTotal())<br>                -&gt;setTaxableAmount(4.00)<br>                -&gt;setTaxAmount(0.60)<br>                -&gt;setTaxCategory($taxCategory);<br><br>            $taxTotal = (new TaxTotal())<br>                -&gt;addTaxSubTotal($taxSubTotal)<br>                -&gt;setTaxAmount(0.60);<br><br>            // === 9. Totals ===<br>            $legalMonetaryTotal = (new LegalMonetaryTotal())<br>                -&gt;setLineExtensionAmount(4.00)<br>                -&gt;setTaxExclusiveAmount(4.00)<br>                -&gt;setTaxInclusiveAmount(4.60)<br>                -&gt;setAllowanceTotalAmount(0)<br>                -&gt;setPrepaidAmount(0)<br>                -&gt;setPayableAmount(4.60);<br><br>            // === 10. Line Items ===<br>            $classifiedTax = (new ClassifiedTaxCategory())<br>                -&gt;setPercent(15)<br>                -&gt;setTaxScheme($taxScheme);<br><br>            $productItem = (new Item())<br>                -&gt;setName(&#39;Product&#39;)<br>                -&gt;setClassifiedTaxCategory($classifiedTax);<br><br>            $price = (new Price())<br>                -&gt;setUnitCode(UnitCode::UNIT)<br>                -&gt;setPriceAmount(2.00);<br><br>            $lineTaxTotal = (new TaxTotal())<br>                -&gt;setTaxAmount(0.60)<br>                -&gt;setRoundingAmount(4.60);<br><br>            $invoiceLine = (new InvoiceLine())<br>                -&gt;setUnitCode(&quot;PCE&quot;)<br>                -&gt;setId(1)<br>                -&gt;setItem($productItem)<br>                -&gt;setLineExtensionAmount(4.00)<br>                -&gt;setPrice($price)<br>                -&gt;setTaxTotal($lineTaxTotal)<br>                -&gt;setInvoicedQuantity(2);<br><br>            // === 11. Build Invoice ===<br>            $invoice = (new Invoice())<br>                -&gt;setUBLExtensions($ublExtensions)<br>                -&gt;setUUID($uuid)<br>                -&gt;setId(&#39;SME00099&#39;)<br>                -&gt;setIssueDate($issueDate)<br>                -&gt;setIssueTime($issueDate)<br>                -&gt;setInvoiceType($invoiceType)<br>                -&gt;setInvoiceCurrencyCode(&#39;SAR&#39;)<br>                -&gt;setTaxCurrencyCode(&#39;SAR&#39;)<br>                -&gt;setAdditionalDocumentReferences($additionalDocs)<br>                -&gt;setAccountingSupplierParty($supplierCompany)<br>                -&gt;setAccountingCustomerParty($supplierCustomer)<br>                -&gt;setDelivery($delivery)<br>                -&gt;setPaymentMeans($paymentMeans)<br>                -&gt;setTaxTotal($taxTotal)<br>                -&gt;setLegalMonetaryTotal($legalMonetaryTotal)<br>                -&gt;setInvoiceLines([$invoiceLine])<br>                -&gt;setSignature($signature);<br><br>            // === 12. Save XML ===<br>            // Generate the invoice XML <br>            $outputPath = storage_path(&#39;zatca/output/Simplified_Invoice.xml&#39;);<br>             $outputXML = GeneratorInvoice::invoice($invoice)-&gt;saveXMLFile($outputPath, null);<br>              echo &quot;Simplified Invoice Generated Successfully\n&quot;; <br>              echo &quot;Invoice saved to: {$outputPath}\n&quot;; <br>              return Command::SUCCESS;<br>          <br>        } catch (\Throwable $e) {<br>            $this-&gt;error(&quot;❌ Error: &quot; . $e-&gt;getMessage());<br>            $this-&gt;line(&quot;File: &quot; . $e-&gt;getFile() . &#39;:&#39; . $e-&gt;getLine());<br>            return Command::FAILURE;<br>        }<br>    }<br>}</pre><p><em>run the following command to generate XML unsigned simplified invoice:</em></p><pre>php artisan zatca:generate-invoice </pre><p><strong>✍️ 4. Signing the Invoice XML</strong></p><p>Before submitting the invoice to ZATCA, we need to digitally sign it using the compliance certificate obtained earlier.</p><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use Illuminate\Console\Command;<br>use Saleh7\Zatca\Helpers\Certificate;<br>use Saleh7\Zatca\InvoiceSigner;<br>use Saleh7\Zatca\Storage;<br><br>class ZatcaSignInvoice extends Command<br>{<br>    /**<br>     * The name and signature of the console command.<br>     *<br>     * @var string<br>     */<br>    protected $signature = &#39;zatca:sign-invoice {invoiceFile=Simplified_Invoice.xml : The invoice XML file to sign}&#39;;<br><br>    /**<br>     * The console command description.<br>     *<br>     * @var string<br>     */<br>    protected $description = &#39;Sign ZATCA invoice XML with the compliance certificate&#39;;<br><br>    /**<br>     * Execute the console command.<br>     */<br>    public function handle()<br>    {<br>        try {<br>            $invoiceFileName = $this-&gt;argument(&#39;invoiceFile&#39;);<br>            <br>            // Load the unsigned invoice XML<br>            $xmlInvoice = (new Storage)-&gt;get(storage_path(&quot;zatca/output/{$invoiceFileName}&quot;));<br>            <br>            echo &quot;Loading unsigned invoice: {$invoiceFileName}\n&quot;;<br>            <br>            // Load the compliance certificate data from the JSON file<br>            $json_certificate = (new Storage)-&gt;get(storage_path(&#39;zatca/output/ZATCA_certificate_data.json&#39;));<br>            <br>            // Decode the JSON data<br>            $json_data = json_decode($json_certificate, true, 512, JSON_THROW_ON_ERROR);<br>            <br>            // Extract certificate details<br>            $certificateContent = $json_data[&#39;certificate&#39;];<br>            $secret = $json_data[&#39;secret&#39;];<br>            <br>            echo &quot;Certificate loaded successfully\n&quot;;<br>            <br>            // Load the private key<br>            $privateKey = file_get_contents(storage_path(&#39;zatca/output/private.pem&#39;));<br>            $cleanPrivateKey = trim(str_replace([&quot;-----BEGIN PRIVATE KEY-----&quot;, &quot;-----END PRIVATE KEY-----&quot;], &quot;&quot;, $privateKey));<br>            <br>            echo &quot;Private key loaded\n&quot;;<br>            <br>            // Create a Certificate instance<br>            $certificate = new Certificate(<br>                $certificateContent,<br>                $cleanPrivateKey,<br>                $secret<br>            );<br>            <br>            echo &quot;Signing the invoice...\n&quot;;<br>            <br>            // Sign the invoice<br>            $signedInvoice = InvoiceSigner::signInvoice($xmlInvoice, $certificate)-&gt;getXML();<br>            <br>            // Save the signed invoice<br>            $signedFileName = str_replace(&#39;.xml&#39;, &#39;_signed.xml&#39;, $invoiceFileName);<br>            (new Storage)-&gt;put(storage_path(&quot;zatca/output/{$signedFileName}&quot;), $signedInvoice);<br>            <br>            echo &quot;Invoice signed successfully!\n&quot;;<br>            echo &quot;Signed invoice saved to: &quot; . storage_path(&quot;zatca/output/{$signedFileName}&quot;) . &quot;\n&quot;;<br>            <br>            return Command::SUCCESS;<br>            <br>        } catch (\Exception $e) {<br>            echo &quot;Error: &quot; . $e-&gt;getMessage() . &quot;\n&quot;;<br>            echo &quot;\nDebug Info:\n&quot;;<br>            echo &quot;File: &quot; . $e-&gt;getFile() . &quot;:&quot; . $e-&gt;getLine() . &quot;\n&quot;;<br>            return Command::FAILURE;<br>        }<br>    }<br>}</pre><p><em>run the following command and add file unsiged invoice name to generate XML signed simplified invoice:</em></p><pre>php artisan zatca:sign-invoice Simplified_Invoice.xml</pre><p><strong>📤 5. Submitting the Signed Invoice to ZATCA</strong></p><p>Once the invoice is digitally signed, it can be submitted to ZATCA’s API for compliance validation.</p><pre>&lt;?php<br><br>namespace App\Console\Commands;<br><br>use Illuminate\Console\Command;<br>use Saleh7\Zatca\Storage;<br>use Sevaske\ZatcaApi\Api;<br>use GuzzleHttp\Client;<br>use Sevaske\ZatcaApi\Exceptions\ZatcaApiException;<br><br><br>class ZatcaSubmitInvoice extends Command<br>{<br>    /**<br>     * The name and signature of the console command.<br>     *<br>     * @var string<br>     */<br>    protected $signature = &#39;zatca:submit-invoice {invoiceFile=Simplified_Invoice_signed.xml : The signed invoice XML file to submit}&#39;;<br><br>    /**<br>     * The console command description.<br>     *<br>     * @var string<br>     */<br>    protected $description = &#39;Submit signed invoice to ZATCA for compliance validation&#39;;<br><br>    /**<br>     * Execute the console command.<br>     */<br>    public function handle()<br>    {<br>        try {<br>            $invoiceFileName = $this-&gt;argument(&#39;invoiceFile&#39;);<br>            <br>            echo &quot;Loading signed invoice: {$invoiceFileName}\n&quot;;<br>            <br>            // Load the signed invoice XML<br>            $signedInvoiceXml = file_get_contents(storage_path(&quot;zatca/output/{$invoiceFileName}&quot;));<br>            <br>            if ($signedInvoiceXml === false) {<br>                throw new \Exception(&quot;Failed to read invoice file: {$invoiceFileName}&quot;);<br>            }<br>            <br>            // Load the compliance certificate data from the JSON file<br>            $json_certificate = (new Storage)-&gt;get(storage_path(&#39;zatca/output/ZATCA_certificate_data.json&#39;));<br>            <br>            // Decode the JSON data<br>            $json_data = json_decode($json_certificate, true, 512, JSON_THROW_ON_ERROR);<br>            <br>            // Extract certificate details<br>            $certificate = $json_data[&#39;certificate&#39;];<br>            $secret = $json_data[&#39;secret&#39;];<br>            <br>            echo &quot;Certificate loaded successfully\n&quot;;<br>            <br>            // Extract UUID and hash from the signed invoice XML<br>            $uuid = $this-&gt;extractUuidFromXml($signedInvoiceXml);<br>            $invoiceHash = $this-&gt;extractHashFromXml($signedInvoiceXml);<br>            echo &quot;Invoice UUID: {$uuid}\n&quot;;<br>            echo &quot;Invoice Hash: {$invoiceHash}\n&quot;;<br>            echo &quot;\n&quot;;<br>            <br>            // Initialize ZATCA API client with credentials<br>            $zatcaClient = new Api(&#39;sandbox&#39;, new Client, $certificate, $secret);<br>            <br>            echo &quot;Submitting invoice to ZATCA (sandbox)...\n&quot;;<br>            echo &quot;Submission type: {$submissionType}\n&quot;;<br>            echo &quot;\n&quot;;<br>            <br>                // Compliance submission (for testing/validation)<br>                $complianceResponse = $zatcaClient-&gt;compliance(<br>                    $signedInvoiceXml,<br>                    $invoiceHash,<br>                    $uuid<br>                );<br>                <br>                echo &quot;✓ Compliance submission successful!\n&quot;;<br>                echo &quot;\nResponse:\n&quot;;<br>                print_r($complianceResponse);<br>            <br>            return Command::SUCCESS;<br>            <br>        } catch (ZatcaApiException $e) {<br>            echo &quot;API Error: &quot; . $e-&gt;getMessage() . &quot;\n&quot;;<br>            <br>            // Try to get more details<br>            if (method_exists($e, &#39;getContext&#39;)) {<br>                $context = $e-&gt;getContext();<br>                if (!empty($context)) {<br>                    echo &quot;\nError Details:\n&quot;;<br>                    print_r($context);<br>                }<br>            }<br>            <br>            echo &quot;\nDebug Info:\n&quot;;<br>            echo &quot;Error Code: &quot; . $e-&gt;getCode() . &quot;\n&quot;;<br>            echo &quot;File: &quot; . $e-&gt;getFile() . &quot;:&quot; . $e-&gt;getLine() . &quot;\n&quot;;<br>            <br>            return Command::FAILURE;<br>        } catch (\Exception $e) {<br>            echo &quot;Error: &quot; . $e-&gt;getMessage() . &quot;\n&quot;;<br>            echo &quot;\nDebug Info:\n&quot;;<br>            echo &quot;File: &quot; . $e-&gt;getFile() . &quot;:&quot; . $e-&gt;getLine() . &quot;\n&quot;;<br>            return Command::FAILURE;<br>        }<br>    }<br>    <br>    /**<br>     * Extract UUID from signed invoice XML<br>     */<br>    private function extractUuidFromXml(string $xml): string<br>    {<br>        $doc = new \DOMDocument();<br>        $doc-&gt;loadXML($xml);<br>        <br>        $xpath = new \DOMXPath($doc);<br>        $xpath-&gt;registerNamespace(&#39;cbc&#39;, &#39;urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2&#39;);<br>        <br>        $uuidNodes = $xpath-&gt;query(&#39;//cbc:UUID&#39;);<br>        if ($uuidNodes-&gt;length &gt; 0) {<br>            return $uuidNodes-&gt;item(0)-&gt;nodeValue;<br>        }<br>        <br>        throw new \Exception(&#39;UUID not found in invoice XML&#39;);<br>    }<br>    <br>    /**<br>     * Extract invoice hash from signed invoice XML<br>     */<br>    private function extractHashFromXml(string $xml): string<br>    {<br>        $doc = new \DOMDocument();<br>        $doc-&gt;loadXML($xml);<br>        <br>        $xpath = new \DOMXPath($doc);<br>        $xpath-&gt;registerNamespace(&#39;ds&#39;, &#39;http://www.w3.org/2000/09/xmldsig#&#39;);<br>        <br>        // Look for DigestValue in the signature<br>        $digestNodes = $xpath-&gt;query(&#39;//ds:Reference[@Id=&quot;invoiceSignedData&quot;]/ds:DigestValue&#39;);<br>        if ($digestNodes-&gt;length &gt; 0) {<br>            return $digestNodes-&gt;item(0)-&gt;nodeValue;<br>        }<br>        <br>        throw new \Exception(&#39;Invoice hash not found in signed XML&#39;);<br>    }<br>}<br><br></pre><pre>php artisan zatca:submit-invoice Simplified_Invoice_signed.xml</pre><p>should be return as the following for the best result :</p><pre>[attributes:protected] =&gt; Array ( [validationResults] =&gt; Array<br> ( [infoMessages] =&gt; Array ( [0] =&gt; Array ( [type] =&gt; INFO [code]<br> =&gt; XSD_ZATCA_VALID [category] =&gt; XSD validation [message]<br> =&gt; Complied with UBL 2.1 standards in line with ZATCA specifications <br>[status] =&gt; PASS ) ) [warningMessages] =&gt; Array ( ) [errorMessages] <br>=&gt; Array ( ) [status] =&gt; PASS ) [reportingStatus]<br> =&gt; REPORTED [clearanceStatus] =&gt; [qrSellertStatus] =&gt; [qrBuyertStatus] =&gt; )</pre><p>For practical guidance, you can explore detailed examples from the official repository of the <a href="https://github.com/sevaske/php-zatca-xml/tree/main/examples"><strong>php-zatca-xml</strong></a> package, available on GitHub.</p><p>This article documents a real implementation journey. The code examples are based on actual working implementations and have been tested.</p><p>Thank you for reading! Happy coding! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3860c56e6b33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficient Image Conversion Media Uploads in Laravel and Filament]]></title>
            <link>https://medium.com/@mamounkamal21_37463/efficient-image-conversion-media-uploads-in-laravel-and-filament-79a2345b19c7?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/79a2345b19c7</guid>
            <category><![CDATA[webp]]></category>
            <category><![CDATA[spatie-media-library]]></category>
            <category><![CDATA[filament]]></category>
            <category><![CDATA[spatie]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Sat, 11 Jan 2025 12:21:27 GMT</pubDate>
            <atom:updated>2025-01-11T12:21:27.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V2LUO77ExtRGNXAP_mQoPw.png" /></figure><p><a href="https://medium.com/@mamounkamal21_37463/convert-images-to-webp-use-spatie-laravel-medialibrary-and-use-ebess-advanced-nova-media-library-to-20a3820165dd"><strong>In our previous article,</strong></a> we discussed how to efficiently upload and optimize images by converting them to WebP format. Today, we will revisit the same library but with a focus on its integration with <strong>Filament</strong>, as well as highlighting some simple changes introduced in <strong>Laravel 11</strong>.</p><p><strong>basic install and setup laravel-medialibrary:</strong></p><p><a href="https://spatie.be/docs/laravel-medialibrary/v11/installation-setup">Base installation | laravel-medialibrary</a></p><p>after install laravel-medialibrary,<strong> Defining media collections (</strong><em>I will use inline comments to explain the workings</em><strong>)</strong></p><pre>class NameModel extends Model implements HasMedia<br>{<br> use InteractsWithMedia; // add this line and implements Has Media<br> public function registerMediaCollections(): void<br> {<br> // this function to register and add your collections<br> // as many collections as needed<br> $this-&gt;addMediaCollection(&#39;my_collection&#39;);<br> /** singleFile() **/ // you can use this function to make upload single image<br> }<br>}</pre><h3>Converting Images to WebP with spatie/laravel-medialibrary</h3><blockquote>The new change here is simple and no longer needs to be used Manipulations::FORMAT_WEBP</blockquote><pre>class NameModel extends Model implements HasMedia<br>{<br>    use InteractsWithMedia;<br><br>    public function registerMediaConversions(Media $media = null): void<br>    {<br>        // add this function to register conversion for media <br>        // and choice what format is it<br>        $this-&gt;addMediaConversion(&#39;media-webp&#39;)<br>            -&gt;format(&#39;webp&#39;)// format webp<br>            -&gt;optimize() // you can add optimize function to <br>                          // Optimizing converted images<br>            -&gt;queued(); // and queued to make it as queue job in background<br>;<br>    }<br>    public function registerMediaCollections(): void<br>    {<br>        $this-&gt;addMediaCollection(&#39;my_collection&#39;)<br>            -&gt;singleFile();<br>    }<br>}</pre><h3>Installing and Setting Up Filament Spatie Media Library Plugin</h3><p>To integrate the filament/spatie-laravel-media-library-plugin package into your Laravel Filament project, follow these steps:</p><h4>Step 1: Install the Plugin</h4><pre>composer require filament/spatie-laravel-media-library-plugin -W</pre><p><strong>Step 2: Publish Migrations</strong></p><pre>php artisan vendor:publish --provider=&quot;Spatie\MediaLibrary\MediaLibraryServiceProvider&quot; --tag=&quot;medialibrary-migrations&quot;<br>php artisan migrate</pre><h4>Step 3: Use the Plugin in Filament Resources</h4><p>In your Filament resource, use the SpatieMediaLibraryFileUpload component.<strong>(</strong><em>I will use inline comments to explain the workings</em><strong>)</strong></p><pre>use Filament\Forms\Components\SpatieMediaLibraryFileUpload;<br><br>// use it as component in form resource <br>SpatieMediaLibraryFileUpload::make(&#39;name lable&#39;)<br>    -&gt;label(__(&#39;Image&#39;))<br>    -&gt;image() // rules to check user upload image <br>    -&gt;collection(&#39;my_collection&#39;) // name collection in model <br>    -&gt;conversion(&#39;media-webp&#39;) // name conversion in model <br>  /**<br>    Additional Options:<br>    -&gt;multiple()       // Allow uploading multiple files<br>    -&gt;downloadable()   // Enable file downloads with a download icon<br>    -&gt;previewable()    // Default: true, show a preview of the uploaded image<br>    -&gt;deletable()      // Allow deleting the uploaded file<br>    -&gt;isDeletable(yourCondition) // Add conditions for deletability<br>    **/<br></pre><h3>Generating responsive images</h3><p>You may <a href="https://spatie.be/docs/laravel-medialibrary/responsive-images/getting-started-with-responsive-images">generate responsive images</a> when the files are uploaded using the responsiveImages() method:</p><pre>SpatieMediaLibraryFileUpload::make(&#39;attachments&#39;)<br>    -&gt;multiple()<br>    -&gt;responsiveImages()</pre><p>Additionally, you can display uploaded images in a Filament table:</p><pre>use Filament\Tables\Columns\SpatieMediaLibraryImageColumn;<br><br>SpatieMediaLibraryImageColumn::make(&#39;image&#39;)<br>    -&gt;collection(&#39;my_collection&#39;) // Specify the collection name<br>    -&gt;label(__(&#39;Image&#39;));</pre><h3>Real-World Example</h3><p>Here’s a practical demonstration of the library’s capabilities:</p><p><strong>Uploaded Image Size:</strong> 6.1 MB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*hMfp_zTRGqRU8qbdGTYFZA.png" /></figure><p><strong>Optimized and Converted to WebP:</strong> 577 KB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*erjtPHzvhTSXpezetJJ4Vg.png" /></figure><p>By converting and optimizing images, you achieve significant reductions in file size, improving application performance and reducing bandwidth usage.</p><h3>References</h3><p>For further details, visit the official plugin documentation:</p><blockquote><a href="https://filamentphp.com/plugins/filament-spatie-media-library">https://filamentphp.com/plugins/filament-spatie-media-library</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79a2345b19c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Revolutionizing Marketing Strategies: Dive into Google Marketing Platform Analytics and Tag…]]></title>
            <link>https://medium.com/@mamounkamal21_37463/revolutionizing-marketing-strategies-dive-into-google-marketing-platform-analytics-and-tag-manager-1d8980e965b1?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d8980e965b1</guid>
            <category><![CDATA[google-marketing-platform]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[google-tag-manager]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[google-analytics]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Sat, 31 Aug 2024 14:53:04 GMT</pubDate>
            <atom:updated>2024-08-31T16:03:43.044Z</atom:updated>
            <content:encoded><![CDATA[<h3>Revolutionizing Marketing Strategies: Dive into Google Marketing Platform Analytics and Tag Manager Integration with Nuxt.js - Part 1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*omjcTd8dvQGus9GocvPKrA.png" /></figure><h4>Embark on a Data Odyssey: Your Guided Journey with Google Marketing Platform(GTM &amp; GA)🚀</h4><p>Welcome aboard, fellow digital explorers! In this exciting parts series, we’re diving deep into the world of Google Marketing Platform (GTM &amp; GA), your trusty companion for tracking and analyzing data like a pro. Get ready to unravel the mysteries of user behavior, enhance your digital product, and chart a course for data-driven success. Join us as we kick off this epic adventure in these parts series.</p><h4>Optimizing Analytics and Tracking with Google Tag Manager</h4><p>In an experimental phase preceding our product launch, I directly integrated it with Google Analytics - a topic we’ll delve into further along the way. Yet, is connecting the product solely to GA truly sufficient, or dare I say, a massive oversight? Thankfully, my realization dawned early, sparing you the intricate specifics. Today, Google Tag Manager (GTM) stands out as a pivotal part of Google’s analytics arsenal. It streamlines event management and effortlessly ushers in updates with each tweak. Moreover, GTM opens avenues to integrate seamlessly with diverse tools and platforms that enhance marketing strategies and streamline tracking processes. No more wrestling with intricate coding for elements like Facebook Pixel, Google Analytics, and a myriad of other tools; GTM simplifies their incorporation onto your site through intuitive steps within its interface.</p><p>Before diving in, allow me to extend a token of appreciation by sharing a valuable gift with you. This Google extension, &quot;<a href="https://chromewebstore.google.com/detail/wappalyzer-technology-pro/gppongmhjkpfnbhagpmjfkannfbllamg?hl=en&amp;pli=1"><strong>Wappalyzer</strong></a>,&quot; serves as a key to unlock insights into the multitude of tools and platforms seamlessly integrated with your website. Its prowess lies in enabling you to discern with precision whether critical components like Google Tag Manager (GTM), Google Analytics (GA), and Facebook Pixel have been successfully woven into the very fabric of your site’s infrastructure.</p><p><strong>Share more insights about </strong><a href="https://support.google.com/tagmanager/answer/14842164?hl=en"><strong>GTM</strong></a><strong>?</strong></p><p>Google Tag Manager, often abbreviated as GTM, is a powerful tool offered by Google that simplifies the process of adding and managing tracking tags and scripts on your website or digital product.</p><p>Imagine your website as a ship sailing through the vast ocean of the internet. Each tag or script you add to your site is like a navigation instrument, helping you understand where you’re going and how you’re getting there. These tags might include tracking codes for analytics, marketing tools, or other third-party services.</p><p>In these exciting parts series, we’ll explore how GTM works, why it’s essential for digital product management, and how you can harness its capabilities to track and analyze data effectively. Whether you’re a seasoned webmaster or just setting sail in the digital world, GTM is your compass for smooth navigation through the seas of data. So, let’s dive in and chart a course to master this invaluable tool.</p><h3>Integrate GTM with Nuxt.js</h3><p>Integrating with GTM enhances website performance by serving as a central hub for connecting tools and platforms. This not only simplifies control but also empowers marketers to link with essential tools seamlessly, without the need for programming intervention or code modifications.</p><p><em>I will use inline comments to explain the workings.</em></p><ul><li>Add @nuxtjs/gtm dependency to your project</li></ul><pre>yarn add @nuxtjs/gtm # or npm install @nuxtjs/gtm</pre><ul><li>Add @nuxtjs/gtm to the modules section of nuxt.config.js</li></ul><pre>export default <br>  modules: [<br>    &#39;@nuxtjs/gtm’,<br>  ],<br>}</pre><ul><li>Create gtm.js file in plugins folder</li></ul><pre> export default function ({<br>  $gtm,<br>  route<br>}) {<br>  $gtm.init(process.env.gtmId)// to get gtm id from differnt env<br>}</pre><p>then add a path to this plugin in plugibs array in nuxt.config.js file</p><pre>plugins: [{<br>      src: &#39;~/plugins/gtm.js’,<br>      mode: &#39;client&#39;<br>    }]</pre><p><em>and add GTMId variables in nuxt.config.js</em></p><pre>env: {<br>  gtmId: process.env.GTM_ID<br>}</pre><ul><li>Add your app container id from GTM in .env file</li></ul><pre>GTM_ID=GTM-XXXXXXX</pre><p>more details about this package 📦 <a href="https://www.npmjs.com/package/@nuxtjs/gtm">@nuxtjs/gtm</a></p><p><strong>In conclusion, </strong>this is a simple guide about GTM without going into the details that we’ll mention in the next series, as well as for GA (Google Analytics). I’d be delighted to hear about your experience and what more you’d like to explore. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d8980e965b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Empowering Growth: Harnessing SmartLook for Comprehensive Product Analytics and User Insights in…]]></title>
            <link>https://medium.com/@mamounkamal21_37463/empowering-growth-harnessing-smartlook-for-comprehensive-product-analytics-and-user-insights-in-a307ac325a0d?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/a307ac325a0d</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[user-insight]]></category>
            <category><![CDATA[product-analytics]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[smartlook]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Wed, 28 Aug 2024 10:33:55 GMT</pubDate>
            <atom:updated>2024-08-28T16:20:34.114Z</atom:updated>
            <content:encoded><![CDATA[<h3>Empowering Growth: Harnessing SmartLook for Comprehensive Product Analytics and User Insights in Nuxt.js</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peneC3yMf8G2VWwDNrzPAQ.png" /><figcaption><a href="https://www.npmjs.com/package/nuxt-smartlook"></a></figcaption></figure><h4>Introduction</h4><p>Discover the power of SmartLook, a robust analytics platform that combines session recordings with event-based insights to offer a comprehensive understanding of user behavior on your mobile app or website. By leveraging session recordings, you can gain clear insights into user interactions, identify issues, and improve the user experience efficiently. With advanced filtering options, you can focus on key moments, uncover errors, and address user concerns promptly. Plus, you can experience SmartLook’s capabilities firsthand by trying it <strong>for free with 3,000 monthly sessions.</strong> Enhance your analytics strategy, track user engagement, and optimize your platform with SmartLook’s valuable features and actionable insights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UMzFH4mLIiAghVzpg_1QLA.jpeg" /><figcaption>SmartLook Panel</figcaption></figure><h4>Installation</h4><p>Start by installing the nuxt-smartlook package using npm:</p><pre> npm install nuxt-smartlook<br></pre><p>Configuration in nuxt.config.js: Add &#39;nuxt-smartlook&#39; to the modules array:</p><pre>module.experts = {<br>modules:[ <br>&#39;nuxt-smartlook&#39;<br>],<br>}<br></pre><p>then add smartlook configuration in nuxt.config.js:</p><pre>// SmartLook configuration <br>   smartlook: {<br>     id: &#39;smartlook*key’,<br>     enabled: process.env.NODE_ENV === &#39;production&#39;<br>   },</pre><blockquote>To obtain your SmartLook key, register at <a href="https://www.smartlook.com/">smartlook.com</a> and navigate to Projects -&gt; Tracking code.</blockquote><h4>Want really powerful reasons to use SmartLook?</h4><p>- sessions recordings</p><p>- use events as filters recordings</p><p>- where and why user drop off (funnels)</p><p>- where your users click and how far they scroll (Heatmaps)</p><p>- Behavior Flows</p><p>- Crash reports.</p><p>smartlook provides dashboards for some statistics and summary results you can customize it as you want about tracking your app or website, Moreover, it provides some comparisons about users by geographic location, browser, gender, device type, country, and provides the percentage of returning users and the most visited pages and <strong>get you important data directly to your inbox.</strong></p><p>Perhaps providing 3000 free sessions per month is a great advantage for startups.</p><p>In addition, for example, once you integrate with smartlook, you can create an event manually from the panel without having to write custom code.</p><p><strong>In conclusion</strong>, integrating SmartLook with your Nuxt.js application is a straightforward process. By following the installation steps and configuring the SmartLook settings in your nuxt.config.js file, you can enhance your analytics capabilities and gain valuable insights into user behavior on your mobile app or website. By leveraging SmartLook, you can track user interactions, identify issues, and optimize the user experience effectively. If you encounter any challenges during the integration process, don’t hesitate to seek further guidance or support. Happy analyzing with SmartLook!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a307ac325a0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Google Sign-in with Nuxt.js 2 — Google Identity]]></title>
            <link>https://medium.com/@mamounkamal21_37463/integrate-google-sign-in-with-nuxt-js-2-google-identity-5411e4581aaa?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5411e4581aaa</guid>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[sign-in-with-google]]></category>
            <category><![CDATA[nuxtjs]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[login]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 06:48:39 GMT</pubDate>
            <atom:updated>2023-08-02T06:48:39.035Z</atom:updated>
            <content:encoded><![CDATA[<h3>Integrate Google Sign-in with Nuxt.js 2 — Google Identity</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*hi5fckZKCE2c2CbDutIwAw.png" /></figure><h3>Introduction</h3><p>Learn how to integrate Google Sign-In functionality into your Nuxt.js 2 applications using the Google Identity platform. Please note that the Google Sign-In JavaScript platform library for Web is deprecated and set to be unsupported after March 31, 2023. While this guide will demonstrate the current library for learning purposes, we strongly recommend transitioning to the new Google Identity Services for Web solution in production applications for enhanced security and user experience. Let’s explore how to set up Google Sign-In in Nuxt.js 2 for seamless authentication.</p><h3>Setup Google Identity</h3><p>To enable Sign In with Google on your website, you first need to set up your Google API client ID. To do so, complete the following steps:</p><p><a href="https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid">Setup | Authentication | Google for Developers</a></p><p>and you can use the <a href="https://developers.google.com/identity/gsi/web/tools/configurator">code generator</a> to easily generate code to embed One Tap, Automatic Sign-in and Sign in with Google button into your web pages.</p><p>Add GSI client in your nuxt.config.js</p><pre>export default {<br>  ...<br>  head: {<br>    ...<br>    script: [<br>      {<br>        src: &#39;https://accounts.google.com/gsi/client&#39;,<br>      },<br>    ],<br>    ...<br>  }<br>  ...<br>}</pre><h4>Load the client library</h4><p>Be sure to load the client library on any page that a user might sign in on. Use the following code snippet:</p><pre>&lt;script src=&quot;https://accounts.google.com/gsi/client&quot; async&gt;&lt;/script&gt;</pre><p><em>I want to add this code in GoogleBtn.vue component to be sure load client library on any page I use GoogleBtn.vue component.</em></p><p>GoogleBtn Component <strong><em>(</em></strong><em>I will use inline comments to explain the workings</em><strong><em>)</em></strong></p><pre>&lt;template&gt;<br>  &lt;v-container class=&quot;px-0&quot;&gt;<br>    &lt;script src=&quot;https://accounts.google.com/gsi/client&quot; async&gt;&lt;/script&gt; // load client libaray<br>    &lt;div class=&quot;google-btn&quot;&gt;<br>      &lt;div<br>        id=&quot;g_id_onload&quot;<br>        data-client_id=&quot;xxxyourclinetappid.apps.googleusercontent.com&quot; // Your clinet id<br>        data-context=&quot;signin&quot;<br>        data-ux_mode=&quot;popup&quot;<br>        data-callback=&quot;SocialLogin&quot;<br>        data-auto_prompt=&quot;false&quot;<br>      /&gt;<br>        // custmization for button from google code generate<br>      &lt;div<br>        class=&quot;g_id_signin&quot;<br>        data-type=&quot;standard&quot;<br>        data-shape=&quot;rectangular&quot;<br>        data-theme=&quot;outline&quot;<br>        data-text=&quot;signin_with&quot;<br>        data-size=&quot;large&quot;<br>        data-logo_alignment=&quot;left&quot;<br>        data-width=&quot;250px&quot;<br>      /&gt;<br>    &lt;/div&gt;<br>  &lt;/v-container&gt;<br>&lt;/template&gt;<br>&lt;style scoped lang=&quot;scss&quot;&gt;<br>.google-btn {<br>  display: flex;<br>  justify-content: center;<br>  @media screen and (max-width: 720px) {<br>    display: flex;<br>    justify-content: center;<br>    margin-bottom: 16px;<br>  }<br>}<br>&lt;/style&gt;</pre><pre>&lt;script&gt;<br>export default {<br>  name: &#39;GoogleBtn&#39;,<br>  beforeMount () {<br>    window.SocialLogin = this.SocialLogin<br>  },<br>  methods: {<br>    // API POST request to send provider and token google user to get profile data by socialite package<br>    SocialLogin (response) {<br>      this.sendEventLogin()<br>      this.$axios.post(&#39;/social-login&#39;, {<br>        provider: &#39;google_jwt&#39;, // provider name <br>        token: response.credential<br>      }, {<br>        headers: {<br>          &#39;Content-Type&#39;: &#39;application/json&#39;<br>        }<br>      }).then((response) =&gt; {<br>        this.$auth.setUserToken(response.data.token)<br>        this.$emit(&#39;loggedIn&#39;)<br>      }).catch((err) =&gt; {<br>        console.log({ err })<br>      })<br>    },<br>  }<br>}<br>&lt;/script&gt;</pre><h4>Conclusion</h4><p>we have successfully integrated Google Sign-In with Nuxt.js 2, providing a seamless and secure authentication experience for our users. However, it’s important to note that the Google Sign-In JavaScript platform library for Web is deprecated after March 31, 2023. We recommend transitioning to the new Google Identity Services for Web solution for continued support and enhanced security. Happy coding!</p><blockquote><em>Main References</em></blockquote><blockquote><a href="https://developers.google.com/identity/gsi/web/guides/overview">https://developers.google.com/identity/gsi/web/guides/overview</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5411e4581aaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrate Amazon SNS into Laravel to Send SMS]]></title>
            <link>https://medium.com/@mamounkamal21_37463/integrate-amazon-sns-into-laravel-to-send-sms-3fcbbe33c109?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fcbbe33c109</guid>
            <category><![CDATA[sms]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[sns]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Sat, 15 Jul 2023 20:26:36 GMT</pubDate>
            <atom:updated>2023-07-15T20:31:20.591Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*Jc5XN__lz-ryhu800RpjZQ.png" /></figure><h3>Introduction</h3><p>In today’s digital age, sending SMS notifications is a common requirement for web applications. Laravel, being a popular PHP framework, offers seamless integration with various third-party services. In this guide, we will explore how to integrate Amazon SNS (Simple Notification Service) into Laravel to send SMS messages. By leveraging the power of Amazon SNS and Laravel’s intuitive features, you can easily incorporate SMS notifications into your Laravel applications.</p><h4>Amazon SNS</h4><p>Amazon SNS (Simple Notification Service) is a fully managed messaging service provided by Amazon Web Services (AWS). It enables developers to build scalable, reliable, and highly available applications by decoupling the components of a distributed system. With Amazon SNS, you can send messages or notifications to various endpoints, such as mobile devices, email, HTTP endpoints, AWS Lambda functions, and more.</p><h4>Key capabilities of Amazon SNS include:</h4><ol><li>Multi-Channel Messaging: Amazon SNS supports multiple messaging protocols, including SMS, email, push notifications, and mobile push notifications. This allows you to reach your users through their preferred communication channels.</li><li>Scalability and Reliability</li><li>Security and Access Control</li></ol><h4>Installing the necessary dependencies via Composer</h4><p>Require the aws-aws-sdk-php-laravel package in your Laravel project</p><pre>composer require aws/aws-sdk-php</pre><p>To register the AWS service provider. Add the line below to the providers key in your config/app.ph</p><pre>&#39;providers&#39; =&gt; array(<br>    // ...<br>    Aws\Laravel\AwsServiceProvider::class,<br>)</pre><p>You should also add the AWS facade alias to the aliases key in your config/app.php</p><pre>&#39;aliases&#39; =&gt; array(<br>     // ...<br>    &#39;AWS&#39; =&gt; Aws\Laravel\AwsFacade::class,<br>)</pre><p>Publish the package’s configuration file using Artisan. This will generate a configuration file in the path config/aws.php.</p><pre>php artisan vendor:publish  --provider=&quot;Aws\Laravel\AwsServiceProvider&quot;</pre><p>Update your credentials and your preferred zone in the generated config/aws.php.</p><pre>&#39;credentials&#39; =&gt; [<br>    &#39;key&#39; =&gt; env(&#39;AWS_SNS_ACCESS_KEY&#39;, &#39;key-xxxxxxx&#39;), // update value and add it in env<br>    &#39;secret&#39; =&gt; env(&#39;AWS_SNS_SECRET_ACCESS_KEY&#39;, &#39;secret-xxxxxx&#39;), // update secret value and add it in env<br>],<br>&#39;region&#39; =&gt; env(&#39;AWS_SNS_REGION&#39;, &#39;eu-central-1&#39;),<br>&#39;version&#39; =&gt; &#39;latest&#39;,<br>&#39;ua_append&#39; =&gt; [<br>    &#39;L5MOD/&#39;.AwsServiceProvider::VERSION,<br>],</pre><blockquote>and add in .envafter update key and value in config/aws.php config file</blockquote><pre>AWS_SNS_ACCESS_KEY=********<br>AWS_SNS_SECRET_ACCESS_KEY=**********************<br>AWS_SNS_REGION=eu-central-1</pre><p>create Action as PHP class <em>app/Actions/SendSMS.php</em></p><pre>&lt;?php<br><br>namespace App\Actions;<br><br>use App\Models\SmsHistory;<br>use App\Models\User;<br>use Aws\Sns\SnsClient;<br><br>class SendSmsAction<br>{<br>      // pass mobile, message and user parameter for invoke method<br>    public function __invoke(string $mobile, string $message, ?User $user = null)<br>    {<br>        //  instance of SnsClient class to configured <br>        // with the necessary credentials and AWS region <br>        $sns = new SnsClient([<br>            &#39;region&#39; =&gt; env(&#39;AWS_SNS_REGION&#39;),<br>            &#39;version&#39; =&gt; &#39;latest&#39;,<br>            &#39;credentials&#39; =&gt; [<br>                &#39;key&#39; =&gt; env(&#39;AWS_SNS_ACCESS_KEY&#39;),<br>                &#39;secret&#39; =&gt; env(&#39;AWS_SNS_SECRET_ACCESS_KEY&#39;),<br>            ],<br>        ]);<br>        // publish method of the SnsClient is called to send the SMS message<br>        $response = $sns-&gt;publish([<br>            &#39;Message&#39; =&gt; $message,<br>            &#39;PhoneNumber&#39; =&gt; $mobile,<br>        ]);<br><br>        // SmsHistory table to store SMS with status       <br>        SmsHistory::query()-&gt;create([<br>            &#39;mobile&#39; =&gt; $mobile,<br>            &#39;message&#39; =&gt; $message,<br>            &#39;status&#39; =&gt; $response[&#39;@metadata&#39;][&#39;statusCode&#39;],<br>            &#39;user_id&#39; =&gt; $user?-&gt;id,<br>        ]);<br>    }<br>}</pre><h4>Conclusion</h4><p>By integrating Amazon SNS into your Laravel application, you can seamlessly send SMS notifications to your users. In this guide, we covered the process of configuring Laravel for Amazon SNS integration, creating a custom service provider, and implementing the functionality to send SMS messages. We also explored advanced features and best practices for utilizing Amazon SNS effectively. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fcbbe33c109" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficient Image Conversion Media Uploads in Laravel: spatie/laravel-medialibrary and…]]></title>
            <link>https://medium.com/@mamounkamal21_37463/convert-images-to-webp-use-spatie-laravel-medialibrary-and-use-ebess-advanced-nova-media-library-to-20a3820165dd?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/20a3820165dd</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[webp]]></category>
            <category><![CDATA[nova]]></category>
            <category><![CDATA[spatie-media-library]]></category>
            <category><![CDATA[image]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Tue, 16 May 2023 16:46:58 GMT</pubDate>
            <atom:updated>2023-05-16T18:32:09.059Z</atom:updated>
            <content:encoded><![CDATA[<h3>Efficient Image Conversion Media Uploads in Laravel: spatie/laravel-medialibrary and ebess/advanced-nova-media-library</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*erVS2bUUtI0Oc-utkAQShA.png" /></figure><h4>Introduction</h4><p>In today’s digital world, managing media files efficiently is essential for web applications. Laravel provides powerful tools and packages that simplify the process of handling media uploads, associating them with models, and converting images to optimize performance. In this article, we will explore the combined use of two popular Laravel packages: <strong>spatie/laravel-medialibrary</strong> and<strong> ebess/advanced-nova-media-library</strong>.</p><p>The <em>spatie/laravel-medialibrary</em> package is a feature-rich solution for managing media files in Laravel applications. It offers an intuitive API to associate various file types, including images, with Eloquent models. One of its key features is the ability to convert images to different formats, such as WebP, which offers superior compression and faster loading times.</p><p>On the other hand, <em>ebess/advanced-nova-media-library</em> is a Laravel Nova field that enhances media management within the Laravel Nova administration panel. With this package, developers can seamlessly display, create, update, and order media files associated with <em>spatie/laravel-medialibrary</em> models.</p><p>In this article, we will walk through the process of installing, configuring, and utilizing these packages to handle media uploads, administer media content, and convert images to WebP format. By the end, you will have a comprehensive understanding of how to leverage the power of <em>spatie/laravel-medialibrary</em> and <em>ebess/advanced-nova-media-library</em> to optimize your media management workflow in Laravel. Let’s get started!</p><h4>Installing and Setting up spatie/laravel-medialibrary</h4><p>Media Library can be installed via Composer:</p><pre>composer require &quot;spatie/laravel-medialibrary:^10.0.0&quot;</pre><p>You need to publish the migration to create the media table:</p><pre>php artisan vendor:publish --provider=&quot;Spatie\MediaLibrary\MediaLibraryServiceProvider&quot; --tag=&quot;migrations&quot;</pre><p>After that, you need to run migrations.</p><pre>php artisan migrate</pre><p>Publishing the <strong>config file</strong> is <strong>optional</strong>:</p><pre>php artisan vendor:publish --provider=&quot;Spatie\MediaLibrary\MediaLibraryServiceProvider&quot; --tag=&quot;config&quot;</pre><p>then add media disk name in <strong>.env </strong>to change<strong> disk name </strong>in<strong> config/media-library.php</strong></p><pre>MEDIA_DISK=s3</pre><p><strong>Defining media collections (</strong><em>I will use inline comments to explain the workings</em><strong>)</strong></p><pre>class NameModel extends Model implements HasMedia<br>{<br>    use InteractsWithMedia;  // add this line and implements Has Media<br><br>    public function registerMediaCollections(): void<br>    {<br>    // this function to register and add your collections<br>    // as many collections as needed<br>        $this-&gt;addMediaCollection(&#39;my_collection&#39;)<br>            -&gt;singleFile();// you can add this line to make upload single image<br>           // and not support upload mulit-media <br>    }<br>}</pre><h4>Converting Images to WebP with spatie/laravel-medialibrary</h4><p>WebP is a highly efficient image format that provides lossy and lossless compression. It offers significant file size reduction compared to formats like JPEG and PNG while maintaining good image quality. In this section, we’ll explore how to convert images to WebP format using the spatie/laravel-medialibrary package. <strong>(</strong><em>I will use inline comments to explain the workings</em><strong>)</strong></p><pre>class NameModel extends Model implements HasMedia<br>{<br>    use InteractsWithMedia;<br><br>    public function registerMediaConversions(Media $media = null): void<br>    {<br>        // add this function to register conversion for media <br>        // and choice what format is it<br>        $this-&gt;addMediaConversion(&#39;media-webp&#39;)<br>            -&gt;format(Manipulations::FORMAT_WEBP); // format webp<br>    }<br>    public function registerMediaCollections(): void<br>    {<br>        $this-&gt;addMediaCollection(&#39;my_collection&#39;)<br>            -&gt;singleFile();<br>    }<br>}</pre><h4>Installing and Setting up ebess/advanced-nova-media-library</h4><p>To integrate the ebess/advanced-nova-media-library package into your Laravel Nova project, follow these steps:</p><ul><li>Advanced nova media library can be installed via Composer:</li></ul><pre>composer require ebess/advanced-nova-media-library</pre><ul><li>then Publishing the <strong>config file</strong></li></ul><pre>php artisan vendor:publish --tag=nova-media-library</pre><ul><li>then in your resource Nova <strong>(</strong><em>I will use inline comments to explain the workings</em><strong>)</strong></li></ul><pre>use Ebess\AdvancedNovaMediaLibrary\Fields\Images;<br><br>class NameResource extends Resource<br>{<br> Images::make(&#39;Image&#39;, &#39;my_collection&#39;) <br>// when use Images field put your collection name<br>}</pre><p><strong>More additional </strong>to<strong> </strong>help you to handle collections in API <strong>(</strong><em>I will use inline comments to explain the workings</em><strong>)</strong></p><pre>class NameModel extends Model implements HasMedia<br>{<br>    use InteractsWithMedia;<br>    <br>    protected $with = [&#39;media&#39;];// enables for you eager loading<br><br>    public function registerMediaConversions(Media $media = null): void<br>    {<br>  <br>        $this-&gt;addMediaConversion(&#39;media-webp&#39;)<br>            -&gt;format(Manipulations::FORMAT_WEBP);<br>    }<br>    public function registerMediaCollections(): void<br>    {<br>        $this-&gt;addMediaCollection(&#39;my_collection&#39;)<br>            -&gt;singleFile();<br>    }<br>    <br><br>    // add this Get Attribute function in you model to helps for you returned <br>    // image in API resourece like as image_url <br>    // (full converted link .webp from your driver like s3)<br>    public function imageUrl(): Attribute<br>    {<br>        return Attribute::get(function () {<br><br>            $media = $this-&gt;getFirstMedia(&#39;my_collection&#39;);<br>            $hasGeneratedConversion = $media?-&gt;hasGeneratedConversion(&#39;media-webp&#39;);<br>            return $media?-&gt;getFullUrl($hasGeneratedConversion ? &#39;media-webp&#39; : &#39;&#39;);<br>        });<br>    }<br>}</pre><p>In the example above, we added the imageUrl method to the model. This method helps retrieve the image URL in the API resource, returning the full converted link with the .webp format from your media driver (e.g., S3).</p><h4>Conclusion</h4><p>In this article has provided a comprehensive guide on handling uploads, managing media content, and <strong>converting images to the WebP format</strong> in Laravel. We have explored the functionality of two powerful packages: <strong>spatie/laravel-medialibrary</strong>, which simplifies file association with Eloquent models, and <strong>ebess/advanced-nova-media-library</strong>, which enhances media management within Laravel Nova.</p><p>By incorporating the <strong>Images field into our Nova resource</strong>, we have streamlined the process of handling image uploads. Furthermore, we have delved into <strong>handling media collections in the API</strong>, <strong>registering conversions</strong>, and <strong>creating a method to retrieve image URLs in the desired format</strong>.</p><p>For more detailed information and advanced usage scenarios, I encourage you to refer to the official documentation of spatie/laravel-medialibrary and ebess/advanced-nova-media-library. Enjoy harnessing the power of these packages to effectively manage media content in your Laravel projects!</p><blockquote>Main References</blockquote><blockquote><a href="https://spatie.be/docs/laravel-medialibrary/v10/introduction">https://spatie.be/docs/laravel-medialibrary/v10/installation-setup</a></blockquote><blockquote><a href="https://github.com/ebess/advanced-nova-media-library">https://github.com/ebess/advanced-nova-media-library</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20a3820165dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A simple Facebook Login Component in Vue JS and use Socialite package in Laravel]]></title>
            <link>https://medium.com/@mamounkamal21_37463/a-simple-facebook-login-component-in-vue-js-and-use-socialite-package-in-larave-1952cf6a1527?source=rss-e72e9c8d8e1e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1952cf6a1527</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[socialite]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[facebook-login]]></category>
            <dc:creator><![CDATA[Mamoun K. Abu Salah]]></dc:creator>
            <pubDate>Tue, 02 May 2023 18:12:59 GMT</pubDate>
            <atom:updated>2023-05-02T21:25:28.259Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*1QAtyN7OQv6IOb149Jg7Sw.png" /></figure><p>In today’s fast-paced world, users expect a seamless and hassle-free experience when interacting with apps and websites. One important aspect of this experience is the ability to quickly and easily log in or sign up using existing credentials, such as social media accounts. In this document, we’ll explore how we implemented sign-in with Facebook in a Nuxt app using Laravel Socialite. We’ll discuss the challenges we faced, the steps we took to overcome them, and provide a step-by-step guide for integrating Socialite into your own Nuxt app. So, whether you’re a developer looking to streamline your users’ experience or a client seeking to simplify your own interaction with web apps, read on to learn how to make sign-in with Facebook a reality in your Nuxt app.</p><p><strong>Let’s start step by step :</strong></p><h4>- Setting Up the Facebook App</h4><p><strong>Meta for Developers (create a business account and create an App)</strong></p><p>To register as a Facebook Developer from this link explains step by step, how to register as a Facebook developer. Once you have registered you will have access to the App Dashboard and all of our products, SDKs, APIs, development tools, and developer documentation. <a href="https://developers.facebook.com/docs/development/register/">https://developers.facebook.com/docs/development/register/</a></p><p>verify your business account then <strong>Create a App</strong>, complete steps from this link: <a href="https://developers.facebook.com/docs/development/create-an-app">https://developers.facebook.com/docs/development/create-an-app</a></p><p>Once you have completed the app creation flow your app will be loaded in the App Dashboard. In <strong>Add a Product</strong> section, (<strong>Facebook Login</strong> Card) click on <strong>Set Up</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0PPd-L4fl3IojOaMh_Zi4g.png" /></figure><p><strong>complete set Up settings for your app</strong>, and <strong>from Basic Settings</strong> you can get to <strong>(App ID and App Secret)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ry2wxJtwWRpZE6oiOEE-mw.png" /></figure><p><em>hint: you can switch your App from develop to live mood when complete registerion steps.</em></p><p><strong>more details: </strong><a href="https://developers.facebook.com/docs/development">https://developers.facebook.com/docs/development</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/174/1*tuwE5kURIWY3KKctXunI1A.png" /></figure><h4>- Implementing the Facebook Login Component</h4><p>Since its code, and I am creating a single file component <em>(I will use inline comments to explain the workings)</em></p><pre>&lt;template&gt;<br>//here you can make your custmization button<br>  &lt;v-container class=&quot;px-0&quot;&gt;<br>    &lt;div class=&quot;facebook-btn&quot;&gt;<br>      &lt;v-btn<br>        color=&quot;#3b5998&quot;<br>        dark<br>        medium<br>        class=&quot;text-none&quot;<br>        @click=&quot;logInWithFacebook&quot;<br>      &gt;<br>        &lt;v-icon class=&quot;mr-2&quot;&gt;mdi-facebook&lt;/v-icon&gt;<br>        &lt;span&gt;Sign in with Facebook&lt;/span&gt;<br>      &lt;/v-btn&gt;<br>    &lt;/div&gt;<br>  &lt;/v-container&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>export default {<br>  name: &#39;FacebookBtn&#39;,<br>  mounted () {<br>    this.loadFacebookSDK(document, &#39;script&#39;, &#39;facebook-jssdk&#39;)<br>    this.initFacebook()<br>    if (this.$store.state.auth.redirect) {<br>      localStorage.setItem(&#39;redirect&#39;, this.$store.state.auth.redirect)<br>    }<br>    window.SocialLogin = this.SocialLogin<br>  },<br>  methods: {<br>    logInWithFacebook () {<br>      window.FB.login(function (response) {<br>        if (response.authResponse) {<br>           // Now you can redirect the user or do an AJAX request <br>          // here I sent authResponse From Facebook to My Request API<br>          this.SocialLogin(response.authResponse)<br>        } else {<br>          console.log(&#39;User cancelled login or did not fully authorize.&#39;)<br>        }<br>      })<br>      return false<br>    },<br>    initFacebook () {<br>      window.fbAsyncInit = function () {<br>        window.FB.init({<br>          appId: &#39;162xxxxxxxxxxxxx&#39;, //App ID, You will need to change this<br>          cookie: true, // This is important, it&#39;s not enabled by default<br>          xfbml: true,<br>          version: &#39;v11.0&#39; // version v16.0<br>        })<br>      }<br>    },<br>    loadFacebookSDK (d, s, id) {<br>      const fjs = d.getElementsByTagName(s)[0]<br>      if (d.getElementById(id)) {<br>        return<br>      }<br>      const js = d.createElement(s)<br>      js.id = id<br>      js.src = &#39;https://connect.facebook.net/en_US/sdk.js&#39;<br>      fjs.parentNode.insertBefore(js, fjs)<br>    },<br>    SocialLogin (response) {<br>//sent name provider with token to Socialite package to get use object<br>      this.$axios.post(&#39;/social-login&#39;, {<br>        provider: &#39;facebook&#39;,<br>        token: response.accessToken<br>      }, {<br>        headers: {<br>          &#39;Content-Type&#39;: &#39;application/json&#39;<br>        }<br>      }).then((response) =&gt; {<br>        // Set the user token in the Vuex store<br>        this.$auth.setUserToken(response.data.token)<br>        this.$emit(&#39;loggedIn&#39;)<br>      }).catch((err) =&gt; {<br>        console.log({ err })<br>      })<br>    },<br>  }<br>}<br>&lt;/script&gt;</pre><p>The component also has the initFacebook() and loadFacebookSDK() methods that initialize and load the Facebook SDK respectively. The initFacebook() method sets up the Facebook SDK by providing the App ID, enabling cookies, and specifying the version. The loadFacebookSDK() method loads the Facebook SDK asynchronously by appending a script tag to the document.</p><p><strong>on the other hand</strong>, Let’s started with Socialite:</p><pre>composer require laravel/socialite</pre><p><strong>more details: </strong><a href="https://laravel.com/docs/10.x/socialite">https://laravel.com/docs/10.x/socialite</a></p><p>or <a href="https://github.com/laravel/socialite">https://github.com/laravel/socialite</a></p><p>than<strong> add in config/services.php</strong></p><pre>  &#39;facebook&#39; =&gt; [<br>      // get it from basic settings facebook app to add it in env <br>        &#39;client_id&#39;     =&gt; env(&#39;FACEBOOK_CLIENT_ID&#39;), <br>        &#39;client_secret&#39; =&gt; env(&#39;FACEBOOK_CLIENT_SECRET&#39;),<br>    ],</pre><p>add<strong> POST Request in routes/api.php</strong> in your Laravel project</p><pre>Route::post(&#39;/social-login&#39;, SocialLoginController::class);</pre><blockquote>and about Logic in<strong> SocialLogincontroller</strong>, I will mention to challenge you face it in Some Social Platform like: Facebook make email is optional for user and we can’t access to another contact information like mobile.</blockquote><pre>class SocialLoginController extends Controller<br>{<br>    public function __invoke(Request $request)<br>    {<br>        // provider name in request is Facebook<br>        $provider = $request-&gt;provider;<br>        $social_user = Socialite::driver($provider)-&gt;userFromToken($request-&gt;token);<br><br>        abort_unless($social_user, 401, __(&#39;auth.failed_login&#39;));<br><br>         // if found use login and if not create user <br>        /** @var SocialUser $social_user */<br>        $user = User::query()-&gt;whereHas(&#39;socialProviderUsers&#39;, function ($query) use ($social_user, $provider) {<br>            $query-&gt;where(&#39;email&#39;, $this-&gt;getEmail($social_user, $provider))<br>                -&gt;where(&#39;provider&#39;, $provider);<br>        })-&gt;first();<br><br>        if (!$user) {<br>            // here you can create user <br>            // (query create on Eloquent Model or fill object)<br>        }<br><br>         // soical provider user table to store and track social user<br>         // user has many social provider user<br>        SocialProviderUser::query()-&gt;updateOrCreate([<br>            &#39;provider_id&#39; =&gt; $social_user-&gt;getId(),<br>            &#39;provider&#39;    =&gt; $provider,<br>        ], [<br>            &#39;last_token&#39; =&gt; $request-&gt;token,<br>            &#39;email&#39;      =&gt; $this-&gt;getEmail($social_user, $provider),<br>            &#39;user_id&#39;    =&gt; $user-&gt;id,<br>        ]);<br>         // return user with token<br>        return UserResource::make($user)-&gt;additional([<br>            &#39;token&#39; =&gt; $user-&gt;createToken(&#39;user&#39;)-&gt;plainTextToken,<br>        ]);<br>    }<br><br>    private function getEmail($social_user, $provider): string<br>    {<br>      // if user prevent access to email or not have email make fake email<br>      // userID@facebook.com<br>        return $social_user-&gt;getEmail() ?? $social_user-&gt;getId().&#39;@&#39;.$provider.&#39;.com&#39;;<br>    }<br>}</pre><p><strong>In conclusion,</strong> integrating social login in your web application using Laravel and Vue.js can provide a more convenient and efficient way for users to sign up or log in. By using Laravel’s Socialite package and Vue.js, you can easily implement social login functionality for various social platforms, such as Facebook. Socialite allows you to authenticate users with OAuth providers, while Vue.js provides a simple and effective way to create a custom button for the social login feature.</p><p>Overall, social login integration can enhance user experience, increase signups, and streamline the registration process for your web application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1952cf6a1527" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>