<?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:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[DoubleD Blog]]></title><description><![CDATA[Guides, projects and experiences.]]></description><link>https://blog.double-d.software/</link><image><url>https://blog.double-d.software/favicon.png</url><title>DoubleD Blog</title><link>https://blog.double-d.software/</link></image><generator>Ghost 5.79</generator><lastBuildDate>Thu, 16 Apr 2026 20:50:20 GMT</lastBuildDate><atom:link href="https://blog.double-d.software/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Multilingual: Easy Laravel localization with Svelte]]></title><description><![CDATA[<p>Once your application reaches international communities localization is a thing to seriously consider. It can vastly improve the accessibility of your site and increase traffic at the same time by making it possible to use by more people!</p><p>As there are always multiple ways to achieve the same thing, in</p>]]></description><link>https://blog.double-d.software/multilingual-easy-laravel-localization-with-svelte/</link><guid isPermaLink="false">67c0f3aabffc7d000114dce8</guid><dc:creator><![CDATA[Skyslycer]]></dc:creator><pubDate>Fri, 28 Feb 2025 07:00:32 GMT</pubDate><media:content url="https://blog.double-d.software/content/images/2025/02/Frame-1.png" medium="image"/><content:encoded><![CDATA[<img src="https://blog.double-d.software/content/images/2025/02/Frame-1.png" alt="Multilingual: Easy Laravel localization with Svelte"><p>Once your application reaches international communities localization is a thing to seriously consider. It can vastly improve the accessibility of your site and increase traffic at the same time by making it possible to use by more people!</p><p>As there are always multiple ways to achieve the same thing, in this case localization, I have compiled <em>the</em> instruction set to use localization with Laravel (and Svelte) without much work! </p><p>This post is largely based on the <a href="https://blog.double-d.software/using-laravel-with-svelte/" rel="noreferrer">first Laravel + Svelte blog</a> post and builds upon it. I recommend checking it out! You can also see the entire code of this guide in my <a href="https://github.com/DoubleD-Software/laravel-svelte/tree/localization?ref=blog.double-d.software" rel="noreferrer">GitHub repository</a>. With that out of the way, let&apos;s get started!</p><h2 id="publishing-missing-language-files">Publishing missing language files</h2><p>By default, Laravel doesn&apos;t expose any languages files, which prevents us from changing any of them. Luckily, there is a neat Artisan command to publish the needed files.</p><figure class="kg-card kg-code-card"><pre><code>php artisan lang:publish</code></pre><figcaption><p><span style="white-space: pre-wrap;">CLI</span></p></figcaption></figure><p>After running the command, you should be able to see a new directory: <code>lang</code>. It contains the following files:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.double-d.software/content/images/2025/02/2025-02-27_23-54.png" class="kg-image" alt="Multilingual: Easy Laravel localization with Svelte" loading="lazy" width="239" height="171"><figcaption><span style="white-space: pre-wrap;">lang/</span></figcaption></figure><p>These are all default Laravel language files for back end validation and similar. </p><h2 id="installing-laravel-translator">Installing <a href="https://github.com/sergix44/laravel-translator-js?ref=blog.double-d.software" rel="noreferrer">Laravel Translator</a></h2><p>To get these files usable in our front end, we have to use a third party package called <code>laravel-translator</code> which lets us access our localized strings within Svelte. To install it, run the following command:</p><figure class="kg-card kg-code-card"><pre><code>npm install -D laravel-translator</code></pre><figcaption><p><span style="white-space: pre-wrap;">CLI</span></p></figcaption></figure><p>Next, we have to update our <code>vite.config.js</code> by adding the <code>laravelTranslator</code> import and adding that to the plugin list. If you started off from the <a href="https://blog.double-d.software/using-laravel-with-svelte/" rel="noreferrer">first Laravel + Svelte blog post</a>, you are able to copy and paste the entire following code. Alternatively add the two changed lines to your config.</p><figure class="kg-card kg-code-card"><pre><code class="language-js">import { defineConfig } from &apos;vite&apos;;
import laravel from &apos;laravel-vite-plugin&apos;;
import { svelte } from &quot;@sveltejs/vite-plugin-svelte&quot;;
import laravelTranslator from &quot;laravel-translator/vite&quot;;

export default defineConfig({
    plugins: [
        laravel({
            input: [&apos;resources/css/app.css&apos;, &apos;resources/js/app.js&apos;],
            refresh: true,
        }),
        svelte({}),
        laravelTranslator(),
    ],
});</code></pre><figcaption><p><span style="white-space: pre-wrap;">vite.config.js</span></p></figcaption></figure><p>Finally, we need to adjust our <code>app.blade.php</code> in the <code>resources/views</code> directory to properly contain the desired language. We need to replace the opening <code>html</code> tag with the following: <code>&lt;html lang=&quot;{{ app()-&gt;getLocale() }}&quot;&gt;</code>. To also add a fallback locale, which is really useful for incomplete community translations, add the following:</p><pre><code class="language-html">&lt;script&gt;
    window.fallbackLocale = &quot;{{ config(&apos;app.fallback_locale&apos;) }}&quot;
&lt;/script&gt;</code></pre><p>Your Blade view should then look something like this:</p><figure class="kg-card kg-code-card"><pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;{{ app()-&gt;getLocale() }}&quot;&gt;
&lt;script&gt;
    window.fallbackLocale = &quot;{{ config(&apos;app.fallback_locale&apos;) }}&quot;
&lt;/script&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, maximum-scale=1.0&quot; /&gt;
    @vite(&apos;resources/js/app.js&apos;)
    @inertiaHead
&lt;/head&gt;
&lt;body&gt;
@inertia
&lt;/body&gt;
&lt;/html&gt;</code></pre><figcaption><p><span style="white-space: pre-wrap;">resources/views/app.blade.php</span></p></figcaption></figure><h2 id="adding-translations">Adding translations</h2><p>Let&apos;s add some translations! You can use two different file types to add translations: <code>JSON</code> and the regular <code>PHP</code> files. Personally, I prefer the JSON approach, but choosing a file type is your decision.</p><p>First, create an <code>en.json</code> file in the <code>lang</code> directory which will contain all our custom translations for the English language. We can now populate it with the different types of localization:</p><figure class="kg-card kg-code-card"><pre><code class="language-json">{
    &quot;projectName&quot;: &quot;Laravel + Svelte&quot;,
    &quot;greeting&quot;: &quot;Hello, World!&quot;,
    &quot;greetingWithName&quot;: &quot;Hello, :name!&quot;,
    &quot;greetingWithAge&quot;: &quot;Hi :name, you are :count year old.|Hi :name, you are :count years old.&quot;,
    &quot;userCount&quot;: &quot;{0}There are no users online!|{1}There is one user online!|[2,Inf]There are :count users online!&quot;
}</code></pre><figcaption><p><span style="white-space: pre-wrap;">lang/en.json</span></p></figcaption></figure><p>This contains simple translation, parameterized translations (<code>:name</code>) and pluralized translations covering most types of translations. Parameters are defined with a leading colon like this: <code>:param</code>. </p><p>If you just want to differentiate between one (1) and many (2+) in your translation, you can simply use a pipe symbol (<code>|</code>) to split the string. The first part will be used when there is only one of the <code>:count</code>, and the second part when there are more than one.</p><p>Additionally, you have the possibility to define translations for exact amounts with <code>{amount}</code> as seen in the <code>userCount</code> translation. Check out the <a href="https://laravel.com/docs/11.x/localization?ref=blog.double-d.software#pluralization" rel="noreferrer">official Laravel documentation</a> to see all possible pluralization techniques.</p><div class="kg-card kg-signup-card kg-width-regular " data-lexical-signup-form style="background-color: #000000; display: none;">
            
            <div class="kg-signup-card-content">
                
                <div class="kg-signup-card-text ">
                    <h2 class="kg-signup-card-heading" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">Sign up for the DoubleD Blog</span></h2>
                    <p class="kg-signup-card-subheading" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">If you have liked this guide so far you should consider subscribing to our free newsletter to always receive the latest guides! Thank you!</span></p>
                    
        <form class="kg-signup-card-form" data-members-form="signup">
            
            <div class="kg-signup-card-fields">
                <input class="kg-signup-card-input" id="email" data-members-email type="email" required="true" placeholder="Your email">
                <button class="kg-signup-card-button kg-style-accent" style="color: #FFFFFF;" type="submit">
                    <span class="kg-signup-card-button-default">Subscribe</span>
                    <span class="kg-signup-card-button-loading"><svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewbox="0 0 24 24">
        <g stroke-linecap="round" stroke-width="2" fill="currentColor" stroke="none" stroke-linejoin="round" class="nc-icon-wrapper">
            <g class="nc-loop-dots-4-24-icon-o">
                <circle cx="4" cy="12" r="3"/>
                <circle cx="12" cy="12" r="3"/>
                <circle cx="20" cy="12" r="3"/>
            </g>
            <style data-cap="butt">
                .nc-loop-dots-4-24-icon-o{--animation-duration:0.8s}
                .nc-loop-dots-4-24-icon-o *{opacity:.4;transform:scale(.75);animation:nc-loop-dots-4-anim var(--animation-duration) infinite}
                .nc-loop-dots-4-24-icon-o :nth-child(1){transform-origin:4px 12px;animation-delay:-.3s;animation-delay:calc(var(--animation-duration)/-2.666)}
                .nc-loop-dots-4-24-icon-o :nth-child(2){transform-origin:12px 12px;animation-delay:-.15s;animation-delay:calc(var(--animation-duration)/-5.333)}
                .nc-loop-dots-4-24-icon-o :nth-child(3){transform-origin:20px 12px}
                @keyframes nc-loop-dots-4-anim{0%,100%{opacity:.4;transform:scale(.75)}50%{opacity:1;transform:scale(1)}}
            </style>
        </g>
    </svg></span>
                </button>
            </div>
            <div class="kg-signup-card-success" style="color: #FFFFFF;">
                Email sent! Check your inbox to complete your signup.
            </div>
            <div class="kg-signup-card-error" style="color: #FFFFFF;" data-members-error></div>
        </form>
        
                    <p class="kg-signup-card-disclaimer" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">No spam. Unsubscribe anytime.</span></p>
                </div>
            </div>
        </div><h2 id="usage">Usage</h2><p>If you are following the <a href="https://blog.double-d.software/using-laravel-with-svelte/" rel="noreferrer">first Laravel + Svelte blog post</a>, you should be familiar with the <code>Index.svelte</code> in the <code>resources/js/Pages/Home</code> directory. We will use that file to test our new translations.</p><p>Firstly, we need to import the various translation functions. Realistically, you will only need two, but it&apos;s good to have seen all of them in use. </p><pre><code class="language-html">&lt;script&gt;
    import {__, t, trans, trans_choice} from &quot;laravel-translator&quot;
&lt;/script&gt;</code></pre><p>Here is an example <code>Index.svelte</code> with all translation functions in use:</p><figure class="kg-card kg-code-card"><pre><code class="language-html">&lt;script&gt;
    import Layout from &quot;../Layouts/App.svelte&quot;
    import {__, t, trans, trans_choice} from &quot;laravel-translator&quot;
    let { name, age } = $props();
&lt;/script&gt;

&lt;Layout&gt;
    &lt;div class=&quot;text-center font-bold text-xl&quot;&gt;
        &lt;h1 class=&quot;text-4xl&quot;&gt;{__(&apos;projectName&apos;)}&lt;/h1&gt;
        &lt;p class=&quot;text-2xl&quot;&gt;{trans(&apos;greeting&apos;)}&lt;/p&gt;
        &lt;p&gt;{t(&apos;greetingWithName&apos;, {name})}&lt;/p&gt;
        &lt;p&gt;{trans_choice(&apos;greetingWithAge&apos;, age, {name})}&lt;/p&gt;
        &lt;p&gt;{trans_choice(&apos;userCount&apos;, 0)}&lt;/p&gt;
        &lt;p&gt;{trans_choice(&apos;userCount&apos;, 1)}&lt;/p&gt;
        &lt;p&gt;{trans_choice(&apos;userCount&apos;, 2)}&lt;/p&gt;
    &lt;/div&gt;
&lt;/Layout&gt;
</code></pre><figcaption><p><span style="white-space: pre-wrap;">resources/js/Pages/Home/Index.svelte</span></p></figcaption></figure><p>The name and age properties are still left over from the first blog post, and we will insert them into translated strings.</p><p>The functions <code>__</code>, <code>t</code> and <code>trans</code> do exactly the same. The first argument is a translation key we defined in the <code>en.json</code>. If required, the second parameter contains all variables to replace in the translations. If your variable and the parameter in the translation are called the same, you can just pass the variable. Otherwise define it as follows: <code>{name: otherName}</code>.</p><p>The pluralization functions behave a little differently. The second parameter is the number which should be localized. That number is then available as the <code>:count</code> parameter in the localization file. The third parameter is the same as the second parameter from the regular function and contains the variables to pass to the localized string.</p><p>With all that figured out, we can try to see it in action by running <code>composer run dev</code>! </p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.double-d.software/content/images/2025/02/2025-02-28_00-12.png" class="kg-image" alt="Multilingual: Easy Laravel localization with Svelte" loading="lazy" width="1916" height="1006" srcset="https://blog.double-d.software/content/images/size/w600/2025/02/2025-02-28_00-12.png 600w, https://blog.double-d.software/content/images/size/w1000/2025/02/2025-02-28_00-12.png 1000w, https://blog.double-d.software/content/images/size/w1600/2025/02/2025-02-28_00-12.png 1600w, https://blog.double-d.software/content/images/2025/02/2025-02-28_00-12.png 1916w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Working example</span></figcaption></figure><p>Moreover, changing the <code>age</code> variable passed down by the back end will have an immediate result in the web page:</p><figure class="kg-card kg-image-card kg-card-hascaption"><img src="https://blog.double-d.software/content/images/2025/02/2025-02-28_00-14.png" class="kg-image" alt="Multilingual: Easy Laravel localization with Svelte" loading="lazy" width="1109" height="395" srcset="https://blog.double-d.software/content/images/size/w600/2025/02/2025-02-28_00-14.png 600w, https://blog.double-d.software/content/images/size/w1000/2025/02/2025-02-28_00-14.png 1000w, https://blog.double-d.software/content/images/2025/02/2025-02-28_00-14.png 1109w" sizes="(min-width: 720px) 720px"><figcaption><span style="white-space: pre-wrap;">Example for working pluralization</span></figcaption></figure><h2 id="adding-another-language">Adding another language</h2><p>Last but not least, we have to add a different language. We <em>are</em> doing localization after all. For this example, I will add German translations. To get started, we have to create a new file in the <code>lang</code> directory, in my case called <code>de.json</code>. Let&apos;s fill it with translated strings!</p><figure class="kg-card kg-code-card"><pre><code class="language-json">{
    &quot;projectName&quot;: &quot;Laravel und Svelte&quot;,
    &quot;greeting&quot;: &quot;Hallo, Welt!&quot;,
    &quot;greetingWithName&quot;: &quot;Hallo, :name!&quot;,
    &quot;greetingWithAge&quot;: &quot;Hi :name, du bist :count Jahr alt.|Hi :name, du bist :count Jahre alt.&quot;,
    &quot;userCount&quot;: &quot;{0}Es sind keine Benutzer online!|{1}Es ist ein Benutzer online!|[2,Inf]Es sind :count Benutzer online!&quot;
}
</code></pre><figcaption><p><span style="white-space: pre-wrap;">lang/de.json</span></p></figcaption></figure><p>Changing the default locale in the <code>.env</code> file to <code>de</code> will change the language on the web page:</p><figure class="kg-card kg-code-card"><pre><code class="language-env">APP_LOCALE=de</code></pre><figcaption><p><span style="white-space: pre-wrap;">.env</span></p></figcaption></figure><p>And indeed, the changes show, and the pluralization works as expected!</p><figure class="kg-card kg-image-card"><img src="https://blog.double-d.software/content/images/2025/02/2025-02-28_00-15.png" class="kg-image" alt="Multilingual: Easy Laravel localization with Svelte" loading="lazy" width="1916" height="1007" srcset="https://blog.double-d.software/content/images/size/w600/2025/02/2025-02-28_00-15.png 600w, https://blog.double-d.software/content/images/size/w1000/2025/02/2025-02-28_00-15.png 1000w, https://blog.double-d.software/content/images/size/w1600/2025/02/2025-02-28_00-15.png 1600w, https://blog.double-d.software/content/images/2025/02/2025-02-28_00-15.png 1916w" sizes="(min-width: 720px) 720px"></figure><p>Furthermore, since we added the fallback locale, any localization keys that haven&apos;t been translated in German, will be shown in the English translation!</p><p>And that&apos;s all! You have successfully added localization to your Laravel and Svelte website! If this guide has intrigued you, I recommend take a look at <a href="https://blog.double-d.software/spice-up-your-ui-with-shadcn/" rel="noreferrer">adding Shadcn-Svelte</a> to that project which provides a great amount of useful and beautiful UI components.</p><p>Lastly, I want to point out that all code used here is publicly available on the <code>localization</code> branch of the <code>laravel-svelte</code> <a href="https://github.com/DoubleD-Software/laravel-svelte/tree/localization?ref=blog.double-d.software" rel="noreferrer">GitHub repository</a>!</p><p>If you liked this guide and want to see more of these in the future and be notified when a new one releases, consider signing up for our free newsletter! Thank you.</p>]]></content:encoded></item><item><title><![CDATA[Spice up your UI with Shadcn-Svelte and Laravel!]]></title><description><![CDATA[<p>The key to fast and efficient development while upholding a great user interface and experience is not only solved by a proper JavaScript framework like Svelte, but also ideally requires a UI element library which contains many different pre-made and beautiful components. Libraries like Bootstrap were very popular and made</p>]]></description><link>https://blog.double-d.software/spice-up-your-ui-with-shadcn/</link><guid isPermaLink="false">67bf3b58bffc7d000114dc2d</guid><dc:creator><![CDATA[Skyslycer]]></dc:creator><pubDate>Wed, 26 Feb 2025 23:15:00 GMT</pubDate><media:content url="https://blog.double-d.software/content/images/2025/02/Component-2.png" medium="image"/><content:encoded><![CDATA[<img src="https://blog.double-d.software/content/images/2025/02/Component-2.png" alt="Spice up your UI with Shadcn-Svelte and Laravel!"><p>The key to fast and efficient development while upholding a great user interface and experience is not only solved by a proper JavaScript framework like Svelte, but also ideally requires a UI element library which contains many different pre-made and beautiful components. Libraries like Bootstrap were very popular and made websites, which used them, easily identifiable. </p><p>With Shadcn and similar a new era of UI libraries began: they don&apos;t just provide you with a massive library with every component you can dream of in it, but they also give you the entire source code for each component which makes it possible to customize them.</p><p>The <a href="https://blog.double-d.software/using-laravel-with-svelte/" rel="noreferrer">last blog</a> post guided you through the installation process of Laravel and Svelte. The code of that guide can be found on GitHub on the master branch: <a href="https://github.com/DoubleD-Software/laravel-svelte?ref=blog.double-d.software">https://github.com/DoubleD-Software/laravel-svelte</a></p><p>This guide will explain the installation process of Shadcn. While it is largely based on the <a href="https://next.shadcn-svelte.com/docs/installation/vite?ref=blog.double-d.software" rel="noreferrer">Vite guide</a> on Shadcn-Svelte&apos;s own website, adding it to Laravel contains a few quirks you need to consider.</p><p>As always, the code of this guide will be made available on the shadcn branch of the  <a href="https://github.com/DoubleD-Software/laravel-svelte/tree/shadcn?ref=blog.double-d.software" rel="noreferrer">GitHub repository</a>.</p><p>Let&apos;s get into it!</p><h2 id="configuration">Configuration</h2><h3 id="js-and-ts-configs">JS and TS configs</h3><p>First we need to add path aliases to the respective configuration files to simplify the import process of our components.</p><p>If you are using JavaScript as the example does, please create a <code>jsconfig.json</code> in the root of the directory.</p>
<figure class="kg-card kg-code-card"><pre><code class="language-json">{
    &quot;compilerOptions&quot;: {
        &quot;paths&quot;: {
            &quot;$lib/*&quot;: [&quot;./resources/js/lib/*&quot;],
            &quot;$lib&quot;: [&quot;./resources/js/lib&quot;]
        }
    }
}
</code></pre><figcaption><p><span style="white-space: pre-wrap;">jsconfig.json</span></p></figcaption></figure><p>Alternatively, if you are using TypeScript, locate your <code>tsconfig.json</code> and <code>tsconfig.app.json</code> and add the required paths.</p>
<figure class="kg-card kg-code-card"><pre><code class="language-js">{
 &quot;files&quot;: [],
 &quot;references&quot;: [
  { &quot;path&quot;: &quot;./tsconfig.app.json&quot; },
  { &quot;path&quot;: &quot;./tsconfig.node.json&quot; }
 ],
 &quot;compilerOptions&quot;: {
  &quot;baseUrl&quot;: &quot;.&quot;,
  &quot;paths&quot;: {
   &quot;$lib&quot;: [&quot;./resources/js/lib&quot;],
   &quot;$lib/*&quot;: [&quot;./resources/js/lib/*&quot;]
  }
 }
}</code></pre><figcaption><p><span style="white-space: pre-wrap;">tsconfig.json</span></p></figcaption></figure><p>And the <code>tsconfig.app.json</code>:</p>
<figure class="kg-card kg-code-card"><pre><code class="language-json">{
 &quot;compilerOptions&quot;: {
  // ...
  &quot;baseUrl&quot;: &quot;.&quot;,
  &quot;paths&quot;: {
   &quot;$lib&quot;: [&quot;./resources/js/lib&quot;],
   &quot;$lib/*&quot;: [&quot;./resources/js/lib/*&quot;]
  }
 }
}</code></pre><figcaption><p><span style="white-space: pre-wrap;">tsconfig.app.json</span></p></figcaption></figure><p>With the language configuration files taken care of, we need to add the path to the Vite config as well.</p><h3 id="vite-config">Vite config</h3><p>Find the <code>vite.config.js</code> and if you are following the other guide, copy and paste the entire following codeblock overwriting the entire file.</p>
<figure class="kg-card kg-code-card"><pre><code class="language-js">import { defineConfig } from &apos;vite&apos;;
import laravel from &apos;laravel-vite-plugin&apos;;
import { svelte } from &quot;@sveltejs/vite-plugin-svelte&quot;;
import path from &quot;path&quot;;

export default defineConfig({
    plugins: [
        laravel({
            input: [&apos;resources/css/app.css&apos;, &apos;resources/js/app.js&apos;],
            refresh: true,
        }),
        svelte({}),
    ],
    resolve: {
        alias: {
            $lib: path.resolve(&quot;./resources/js/lib&quot;),
        },
    },
});</code></pre><figcaption><p><span style="white-space: pre-wrap;">vite.config.js</span></p></figcaption></figure><blockquote>If you are adding this to your own Vite config, do not forget to add the <code>path</code> import!</blockquote><h2 id="installation">Installation</h2><p>Now we are ready to install Shadcn! Or at least initialize the required files, since Shadcn doesn&apos;t really &quot;install&quot; itself in your code base. In order to do that run the following command. When using <code>pnpm</code> you are able to use <code>pnpm dlx</code> instead of <code>npx</code>.</p><figure class="kg-card kg-code-card"><pre><code>npx shadcn-svelte@next init</code></pre><figcaption><p><span style="white-space: pre-wrap;">CLI</span></p></figcaption></figure><p>In the selection prompt chose everything according to your project settings. If you are using JS, select JS, if not, select TS. Simple as that.</p><p>If the Shadcn installer didn&apos;t recognize your <code>app.css</code> immediately, you can simply set it to the path <code>resources/css/app.css</code>.</p><h3 id="fixing-tailwindcss">Fixing TailwindCSS</h3><p>To add its own styles, Shadcn overwrote your <code>tailwind.config.js</code>. The issue specifically lies in the overwritten <code>content</code> tag. It now doesn&apos;t contain the correct extensions anymore, which leads to TailwindCSS breaking entirely. So let&apos;s fix it!</p><p>Switch the <code>content</code> tag in your TCSS config back to the original value:</p><figure class="kg-card kg-code-card"><pre><code class="language-js">    content: [
        &apos;./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php&apos;,
        &apos;./storage/framework/views/*.php&apos;,
        &apos;./resources/**/*.blade.php&apos;,
        &apos;./resources/**/*.js&apos;,
        &apos;./resources/**/*.svelte&apos;,
    ],</code></pre><figcaption><p><span style="white-space: pre-wrap;">tailwind.config.js</span></p></figcaption></figure><div class="kg-card kg-callout-card kg-callout-card-red"><div class="kg-callout-text">Remember to only overwrite the content key! If you remove anything else it is very likely that Shadcn won&apos;t work!</div></div><p>With all that tedious configuration work done, we can finally start using Shadcn components with Svelte and Laravel!</p><div class="kg-card kg-signup-card kg-width-regular " data-lexical-signup-form style="background-color: #000000; display: none;">
            
            <div class="kg-signup-card-content">
                
                <div class="kg-signup-card-text ">
                    <h2 class="kg-signup-card-heading" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">Sign up for DoubleD Blog</span></h2>
                    <p class="kg-signup-card-subheading" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">If you have liked this guide up until now, consider subscribing for free for more guides like these!</span></p>
                    
        <form class="kg-signup-card-form" data-members-form="signup">
            
            <div class="kg-signup-card-fields">
                <input class="kg-signup-card-input" id="email" data-members-email type="email" required="true" placeholder="Your email">
                <button class="kg-signup-card-button kg-style-accent" style="color: #FFFFFF;" type="submit">
                    <span class="kg-signup-card-button-default">Subscribe</span>
                    <span class="kg-signup-card-button-loading"><svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewbox="0 0 24 24">
        <g stroke-linecap="round" stroke-width="2" fill="currentColor" stroke="none" stroke-linejoin="round" class="nc-icon-wrapper">
            <g class="nc-loop-dots-4-24-icon-o">
                <circle cx="4" cy="12" r="3"/>
                <circle cx="12" cy="12" r="3"/>
                <circle cx="20" cy="12" r="3"/>
            </g>
            <style data-cap="butt">
                .nc-loop-dots-4-24-icon-o{--animation-duration:0.8s}
                .nc-loop-dots-4-24-icon-o *{opacity:.4;transform:scale(.75);animation:nc-loop-dots-4-anim var(--animation-duration) infinite}
                .nc-loop-dots-4-24-icon-o :nth-child(1){transform-origin:4px 12px;animation-delay:-.3s;animation-delay:calc(var(--animation-duration)/-2.666)}
                .nc-loop-dots-4-24-icon-o :nth-child(2){transform-origin:12px 12px;animation-delay:-.15s;animation-delay:calc(var(--animation-duration)/-5.333)}
                .nc-loop-dots-4-24-icon-o :nth-child(3){transform-origin:20px 12px}
                @keyframes nc-loop-dots-4-anim{0%,100%{opacity:.4;transform:scale(.75)}50%{opacity:1;transform:scale(1)}}
            </style>
        </g>
    </svg></span>
                </button>
            </div>
            <div class="kg-signup-card-success" style="color: #FFFFFF;">
                Email sent! Check your inbox to complete your signup.
            </div>
            <div class="kg-signup-card-error" style="color: #FFFFFF;" data-members-error></div>
        </form>
        
                    <p class="kg-signup-card-disclaimer" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">No spam. Unsubscribe anytime.</span></p>
                </div>
            </div>
        </div><h2 id="usage">Usage</h2><p>Let&apos;s begin with the simplest component of them all: the button.</p><blockquote>You can take a look at all different components on <a href="https://next.shadcn-svelte.com/docs/components/accordion?ref=blog.double-d.software" rel="noreferrer">Shadcn-Svelte&apos;s website</a>!</blockquote><p>To add that component to your code base, you run the following command. You can again replace <code>npx</code> with <code>pnpm dlx</code> when using PNPM.</p><figure class="kg-card kg-code-card"><pre><code>npx shadcn-svelte@next add button</code></pre><figcaption><p><span style="white-space: pre-wrap;">CLI</span></p></figcaption></figure><p>After going through the prompts you should have your component at the ready! Let&apos;s add it to our <code>Index.svelte</code> which we have created in the previous guide!</p><figure class="kg-card kg-code-card"><pre><code class="language-html">&lt;script&gt;
    import Layout from &quot;../Layouts/App.svelte&quot;
    import { Button } from &quot;$lib/components/ui/button/index.js&quot;;
    let { name, age } = $props();
&lt;/script&gt;

&lt;Layout&gt;
    &lt;div class=&quot;text-center font-bold text-4xl&quot;&gt;
        &lt;h1&gt;Laravel + Svelte&lt;/h1&gt;
        &lt;p class=&quot;text-2xl&quot;&gt;Hello {name} ({age})&lt;/p&gt;
        &lt;Button&gt;Click me&lt;/Button&gt;
    &lt;/div&gt;
&lt;/Layout&gt;</code></pre><figcaption><p><span style="white-space: pre-wrap;">Home/Index.svelte</span></p></figcaption></figure><p>Here we can see our custom path <code>$lib</code>! Your IDE should automatically import the right file when trying to use the <code>Button</code> component. Make sure you aren&apos;t importing it from <code>bits-ui</code> though!</p><p>With that out of the way and a simple component added to our main page, we can start the development server.</p><figure class="kg-card kg-code-card"><pre><code>composer run dev</code></pre><figcaption><p><span style="white-space: pre-wrap;">CLI</span></p></figcaption></figure><p>You can configure which commands <code>composer</code> runs in your <code>composer.json</code> if you want to run PNPM instead of NPM!</p><p>After the development server spun up, you can open up your website and take a look and your new button!</p><figure class="kg-card kg-image-card"><img src="https://blog.double-d.software/content/images/2025/02/Pasted-image.png" class="kg-image" alt="Spice up your UI with Shadcn-Svelte and Laravel!" loading="lazy" width="1919" height="970" srcset="https://blog.double-d.software/content/images/size/w600/2025/02/Pasted-image.png 600w, https://blog.double-d.software/content/images/size/w1000/2025/02/Pasted-image.png 1000w, https://blog.double-d.software/content/images/size/w1600/2025/02/Pasted-image.png 1600w, https://blog.double-d.software/content/images/2025/02/Pasted-image.png 1919w" sizes="(min-width: 720px) 720px"></figure><p>Currently, it is not the best looking, but it&apos;s proof that it works! Your imagination should do the rest! Have fun with Shadcn!</p><p>If you encounter any issues or have questions regarding this or any other guides and blog posts, consider joining our DoubleD Software Discord server: <a href="https://discord.gg/2kGR3AdfZH?ref=blog.double-d.software">https://discord.gg/2kGR3AdfZH</a></p><p>In case you want to check out the code for this guide, take a look at the <code>shadcn</code> branch of the <a href="https://github.com/DoubleD-Software/laravel-svelte/tree/shadcn?ref=blog.double-d.software" rel="noreferrer">repository</a>!</p><p>Thanks for reading this blog post! Consider subscribing (free) to our newsletter to always receive a notification when we publish a new useful guide! Thank you!</p>]]></content:encoded></item><item><title><![CDATA[Using Laravel with Svelte]]></title><description><![CDATA[<p>Laravel, an extensive PHP web application framework with many features already baked in from the beginning, is steadily increasing in popularity. Similarly, Svelte, yet another JS framework for the front end, is seeing more and more adoption. </p><p>Unfortunately, Laravel currently only provides default setups for other major frameworks: React and</p>]]></description><link>https://blog.double-d.software/using-laravel-with-svelte/</link><guid isPermaLink="false">67571f2bbffc7d000114daca</guid><dc:creator><![CDATA[Skyslycer]]></dc:creator><pubDate>Mon, 09 Dec 2024 18:38:09 GMT</pubDate><media:content url="https://blog.double-d.software/content/images/2024/12/Component-2--2-.png" medium="image"/><content:encoded><![CDATA[<img src="https://blog.double-d.software/content/images/2024/12/Component-2--2-.png" alt="Using Laravel with Svelte"><p>Laravel, an extensive PHP web application framework with many features already baked in from the beginning, is steadily increasing in popularity. Similarly, Svelte, yet another JS framework for the front end, is seeing more and more adoption. </p><p>Unfortunately, Laravel currently only provides default setups for other major frameworks: React and Vue. While this is unfortunate, the endless configuration options in the web space have given us the possibility to use Laravel with Svelte. The main contributor to this solution is <a href="https://v2.inertiajs.com/?ref=blog.double-d.software" rel="noreferrer">InertiaJS</a>, which not only provides React and Vue support to Laravel, but also supports Svelte.</p><p>After wanting to start out in the world of Laravel using my favorite JS framework Svelte, I was stumped to find out that other than a few sparsely documented wiki pages and outdated blog posts, there was no information on how to set up a project from the start. </p><p>This lead to me creating this blog post, which sums up, what I believe is all the step-by-step information you need to start out with your Laravel project using Svelte. It not only covers the basics of installing it, but also goes over other specific cases like <strong>passing data from Laravel to Svelte</strong> and <strong>using layouts</strong> where my research lead to me piecing this information together from multiple different sources and posts.</p><p>You can find the accompanying repository on my GitHub: <a href="https://github.com/DoubleD-Software/laravel-svelte?ref=blog.double-d.software" rel="noreferrer">https://github.com/DoubleD-Software/laravel-svelte</a></p><p>Let&apos;s get started!</p><h1 id="creating-a-new-project-adding-svelte">Creating a new project &amp; adding Svelte</h1><h2 id="installing-laravel">Installing Laravel</h2><p>If not already done, you should install Laravel and all tools required to run it according to the official installation instructions.</p><figure class="kg-card kg-code-card"><pre><code class="language-sh">/bin/bash -c &quot;$(curl -fsSL https://php.new/install/mac/8.3)&quot;</code></pre><figcaption><p><span style="white-space: pre-wrap;">MacOS installation script</span></p></figcaption></figure><figure class="kg-card kg-code-card"><pre><code class="language-ps"># Run as administrator...
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString(&apos;https://php.new/install/windows/8.3&apos;))</code></pre><figcaption><p><span style="white-space: pre-wrap;">Windows PowerShell installation script</span></p></figcaption></figure><figure class="kg-card kg-code-card"><pre><code class="language-sh">/bin/bash -c &quot;$(curl -fsSL https://php.new/install/linux/8.3)&quot;</code></pre><figcaption><p><span style="white-space: pre-wrap;">Linux installation script</span></p></figcaption></figure><p>If you already have PHP and Composer installed, you can use this command to install the Laravel installer:</p><pre><code class="language-sh">composer global require laravel/installer</code></pre><p>After you have installed Laravel, close your terminal and reopen it. You should now have access to the <code>laravel</code> command.</p><h2 id="creating-a-new-project">Creating a new project</h2><p>We have to create a new Laravel project to work in. Move to your projects directory, or anywhere where you want your project to be created in. Then run this command, replacing <code>laravel-svelte</code> with the name of your project. Afterwards, move to the project directory.</p><pre><code class="language-sh ">laravel new laravel-svelte
cd laravel-svelte</code></pre><p>You can just select the default option in all prompts. This means: no starter kit, Pest as the testing framework, SQLite as the database and &quot;Yes, I want to run the default database migrations&quot;.</p><h2 id="installing-inertiajs-on-the-server-side">Installing InertiaJS on the server side</h2><h3 id="installing-inertiajs">Installing InertiaJS</h3><p>To support the latest version of Svelte, we currently have to install a development version of InertiaJS 2. Once this version has released, you can use that instead of the development version.</p><figure class="kg-card kg-code-card"><pre><code class="language-sh">composer require inertiajs/inertia-laravel</code></pre><figcaption><p><span style="white-space: pre-wrap;">Installing InertiaJS 2</span></p></figcaption></figure><h3 id="populating-the-appbladephp">Populating the <code>app.blade.php</code></h3><p>Now you can delete the <code>welcome.blade.php</code> in <code>resources/views/</code> and create a new file in that same directory called <code>app.blade.php</code>, which you can populate with the following code. This will tell InertiaJS where it can insert its content.</p><figure class="kg-card kg-code-card"><pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot; /&gt;
    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, maximum-scale=1.0&quot; /&gt;
    @vite(&apos;resources/js/app.js&apos;)
    @inertiaHead
&lt;/head&gt;
&lt;body&gt;
@inertia
&lt;/body&gt;
&lt;/html&gt;
</code></pre><figcaption><p><span style="white-space: pre-wrap;">resources/views/app.blade.php</span></p></figcaption></figure><h3 id="installing-the-required-middle-ware">Installing the required middle ware</h3><p>For InertiaJS to work properly on the server side, we have to add its middle ware. This is simply done using this command:</p><pre><code class="language-sh">php artisan inertia:middleware</code></pre><p>Additionally, you have to add the middle ware to the <code>bootstrap/app.php</code> file. If your project is still fresh, you can just copy and paste the following code:</p><figure class="kg-card kg-code-card"><pre><code class="language-php">&lt;?php

use App\Http\Middleware\HandleInertiaRequests;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    -&gt;withRouting(
        web: __DIR__.&apos;/../routes/web.php&apos;,
        commands: __DIR__.&apos;/../routes/console.php&apos;,
        health: &apos;/up&apos;,
    )-&gt;withMiddleware(function (Middleware $middleware) {
        $middleware-&gt;web(append: [
            HandleInertiaRequests::class,
        ]);
    })-&gt;withExceptions()-&gt;create();</code></pre><figcaption><p><span style="white-space: pre-wrap;">bootstrap/app.php (note the InertiaJS middle ware)</span></p></figcaption></figure><p>With all this done, we can now move on to the client side.</p><h2 id="installing-svelte-and-inertiajs-on-the-client-side">Installing Svelte and InertiaJS on the client side</h2><h3 id="installing-all-required-packages">Installing all required packages</h3><p>For this to work, we need to install the following packages: Svelte, the Vite plugin for Svelte, InertiaJS&apos;s Svelte adapter and Vite 6 or higher. This should resolve without any dependency conflicts.</p><figure class="kg-card kg-code-card"><pre><code class="language-sh">npm install svelte
npm install @sveltejs/vite-plugin-svelte
npm install @inertiajs/svelte
npm install vite@6.0.0</code></pre><figcaption><p><span style="white-space: pre-wrap;">Installing the required packages</span></p></figcaption></figure><h3 id="populating-the-appjs">Populating the <code>app.js</code></h3><p>You can overwrite the current content of the <code>resources/js/app.js</code> file with the following content. It defines where InertiaJS will look for files to interpret.</p><figure class="kg-card kg-code-card"><pre><code class="language-js">import { createInertiaApp } from &apos;@inertiajs/svelte&apos;
import { mount } from &apos;svelte&apos;
import &apos;../css/app.css&apos;

createInertiaApp({
  resolve: name =&gt; {
    const pages = import.meta.glob(&apos;./Pages/**/*.svelte&apos;, { eager: true })
    return pages[`./Pages/${name}.svelte`]
  },
  setup({ el, App, props }) {
    mount(App, { target: el, props })
  },
})
</code></pre><figcaption><p><span style="white-space: pre-wrap;">resources/js/app.js</span></p></figcaption></figure><p>Furthermore, you can delete the <code>resources/js/bootstrap.js</code> file, this will have no repercussions.</p><h3 id="configuring-vite-and-tailwindcss">Configuring Vite and TailwindCSS</h3><p>Copy and paste the following into the <code>vite.config.js</code> file in the root of the project directory. </p><figure class="kg-card kg-code-card"><pre><code class="language-js">import { defineConfig } from &apos;vite&apos;;
import laravel from &apos;laravel-vite-plugin&apos;;
import { svelte } from &quot;@sveltejs/vite-plugin-svelte&quot;;

export default defineConfig({
    plugins: [
        laravel({
            input: [&apos;resources/css/app.css&apos;, &apos;resources/js/app.js&apos;],
            refresh: true,
        }),
        svelte({})
    ],
});</code></pre><figcaption><p><span style="white-space: pre-wrap;">vite.config.js</span></p></figcaption></figure><p>Afterwards, overwrite the <code>tailwindcss.config.js</code> with the following content:</p><figure class="kg-card kg-code-card"><pre><code class="language-js">/** @type {import(&apos;tailwindcss&apos;).Config} */
export default {
    content: [
        &apos;./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php&apos;,
        &apos;./storage/framework/views/*.php&apos;,
        &apos;./resources/**/*.blade.php&apos;,
        &apos;./resources/**/*.js&apos;,
        &apos;./resources/**/*.svelte&apos;,
    ],
    plugins: [],
};</code></pre><figcaption><p><span style="white-space: pre-wrap;">tailwindcss.config.js</span></p></figcaption></figure><p>And with that, the installation part of this guide is done. Let&apos;s move on to the usage.</p><div class="kg-card kg-signup-card kg-width-regular " data-lexical-signup-form style="background-color: #000000; display: none;">
            
            <div class="kg-signup-card-content">
                
                <div class="kg-signup-card-text ">
                    <h2 class="kg-signup-card-heading" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">Sign up for the DoubleD Blog</span></h2>
                    <p class="kg-signup-card-subheading" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">If you&apos;ve liked this guide so far, you might want to subscribe for more of this content!</span></p>
                    
        <form class="kg-signup-card-form" data-members-form="signup">
            
            <div class="kg-signup-card-fields">
                <input class="kg-signup-card-input" id="email" data-members-email type="email" required="true" placeholder="Your email">
                <button class="kg-signup-card-button kg-style-accent" style="color: #FFFFFF;" type="submit">
                    <span class="kg-signup-card-button-default">Subscribe</span>
                    <span class="kg-signup-card-button-loading"><svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewbox="0 0 24 24">
        <g stroke-linecap="round" stroke-width="2" fill="currentColor" stroke="none" stroke-linejoin="round" class="nc-icon-wrapper">
            <g class="nc-loop-dots-4-24-icon-o">
                <circle cx="4" cy="12" r="3"/>
                <circle cx="12" cy="12" r="3"/>
                <circle cx="20" cy="12" r="3"/>
            </g>
            <style data-cap="butt">
                .nc-loop-dots-4-24-icon-o{--animation-duration:0.8s}
                .nc-loop-dots-4-24-icon-o *{opacity:.4;transform:scale(.75);animation:nc-loop-dots-4-anim var(--animation-duration) infinite}
                .nc-loop-dots-4-24-icon-o :nth-child(1){transform-origin:4px 12px;animation-delay:-.3s;animation-delay:calc(var(--animation-duration)/-2.666)}
                .nc-loop-dots-4-24-icon-o :nth-child(2){transform-origin:12px 12px;animation-delay:-.15s;animation-delay:calc(var(--animation-duration)/-5.333)}
                .nc-loop-dots-4-24-icon-o :nth-child(3){transform-origin:20px 12px}
                @keyframes nc-loop-dots-4-anim{0%,100%{opacity:.4;transform:scale(.75)}50%{opacity:1;transform:scale(1)}}
            </style>
        </g>
    </svg></span>
                </button>
            </div>
            <div class="kg-signup-card-success" style="color: #FFFFFF;">
                Email sent! Check your inbox to complete your signup.
            </div>
            <div class="kg-signup-card-error" style="color: #FFFFFF;" data-members-error></div>
        </form>
        
                    <p class="kg-signup-card-disclaimer" style="color: #FFFFFF;"><span style="white-space: pre-wrap;">Free. No spam. Unsubscribe anytime.</span></p>
                </div>
            </div>
        </div><h1 id="using-svelte-in-laravel">Using Svelte in Laravel</h1><h2 id="basic-page-rendering">Basic page rendering</h2><h3 id="creating-a-new-svelte-file">Creating a new Svelte file</h3><p>For InertiaJS to be able to render your Svelte files, you first have to create a <code>Pages</code> (yes, capital P) directory in the <code>resources/js/</code> folder. In there, you can create another folder called <code>Home</code>, where you then create the first Svelte file called <code>Index.svelte</code>. Usually, developers use the folders like <code>Home</code> to differentiate between different items in a REST API. In this case, this will just return a simple website with the following code:</p><figure class="kg-card kg-code-card"><pre><code class="language-html">&lt;div class=&quot;text-center font-bold text-4xl&quot;&gt;
    &lt;h1&gt;Laravel + Svelte&lt;/h1&gt;
&lt;/div&gt;</code></pre><figcaption><p><span style="white-space: pre-wrap;">resources/js/Pages/Home/Index.svelte</span></p></figcaption></figure><p>Note how we can use TailwindCSS right out of the box!</p><h3 id="rendering-the-new-svelte-file">Rendering the new Svelte file</h3><p>Now you can render this page on the <code>/</code> route by replacing it with the following code in the <code>routes/web.php</code>:</p><figure class="kg-card kg-code-card"><pre><code class="language-php">&lt;?php

use Illuminate\Support\Facades\Route;
use Inertia\Inertia;

Route::get(&apos;/&apos;, function () {
    return Inertia::render(&apos;Home/Index&apos;);
});</code></pre><figcaption><p><span style="white-space: pre-wrap;">routes/web.php</span></p></figcaption></figure><p>See how you only have to define the directory from the <code>Pages</code> folder and up. You also don&apos;t need to use the <code>.svelte</code> extension.</p><h3 id="running-the-server">Running the server</h3><p>For good measure, you can run both Composer and NPM install commands to be sure that all dependencies are up to date.</p><pre><code class="language-sh">npm install
composer install</code></pre><p>The following command will then run <code>npm run dev</code> and <code>php artisan serve</code> simultaneously. This will start the development server and is usually on <code>http://localhost:8000</code>, but check your console for your port.</p><figure class="kg-card kg-code-card"><pre><code class="language-sh">composer run dev</code></pre><figcaption><p><span style="white-space: pre-wrap;">This command will run the development server</span></p></figcaption></figure><p>Going to this page in your browser should yield the following result (500% zoomed):</p><figure class="kg-card kg-image-card"><img src="https://blog.double-d.software/content/images/2024/12/2024-12-09_17-03.png" class="kg-image" alt="Using Laravel with Svelte" loading="lazy" width="1916" height="441" srcset="https://blog.double-d.software/content/images/size/w600/2024/12/2024-12-09_17-03.png 600w, https://blog.double-d.software/content/images/size/w1000/2024/12/2024-12-09_17-03.png 1000w, https://blog.double-d.software/content/images/size/w1600/2024/12/2024-12-09_17-03.png 1600w, https://blog.double-d.software/content/images/2024/12/2024-12-09_17-03.png 1916w" sizes="(min-width: 720px) 720px"></figure><p>Congratulations! You have successfully visited your first Laravel + Svelte site. </p><h2 id="passing-data">Passing data</h2><p>Passing data to the front end in Laravel is very straight forward, but it isn&apos;t very clear what you have to do in the Svelte code base to <em>use</em> that data.</p><h3 id="laravel-side">Laravel side</h3><p>As previously mentioned, this is fairly simple. Simply modify the route <code>routes/web.php</code> as shows below, which will return two properties to the Svelte site.</p><figure class="kg-card kg-code-card"><pre><code class="language-php">Route::get(&apos;/&apos;, function () {
    return Inertia::render(&apos;Home/Index&apos;, [
        &apos;name&apos; =&gt; &apos;John Doe&apos;,
        &apos;age&apos; =&gt; 30,
    ]);
});</code></pre><figcaption><p><span style="white-space: pre-wrap;">routes/web.php</span></p></figcaption></figure><h3 id="svelte-side">Svelte side</h3><p>To receive the data, you simply have to use the <code>$props()</code> function in Svelte as the following example shows:</p><figure class="kg-card kg-code-card"><pre><code class="language-html">&lt;script&gt;
    let { name, age } = $props();
&lt;/script&gt;

&lt;div class=&quot;text-center font-bold text-4xl&quot;&gt;
    &lt;h1&gt;Laravel + Svelte&lt;/h1&gt;
    &lt;p class=&quot;text-2xl&quot;&gt;Hello {name} ({age})&lt;/p&gt;
&lt;/div&gt;</code></pre><figcaption><p><span style="white-space: pre-wrap;">resources/js/Pages/Home/Index.svelte</span></p></figcaption></figure><p>With that defined in the <code>script</code> tag, you can use the data wherever you want in your Svelte file in the traditional fashion. </p><p>The website should now look like this (500% zoomed). Simple, isn&apos;t it? </p><figure class="kg-card kg-image-card"><img src="https://blog.double-d.software/content/images/2024/12/2024-12-09_17-19.png" class="kg-image" alt="Using Laravel with Svelte" loading="lazy" width="1917" height="615" srcset="https://blog.double-d.software/content/images/size/w600/2024/12/2024-12-09_17-19.png 600w, https://blog.double-d.software/content/images/size/w1000/2024/12/2024-12-09_17-19.png 1000w, https://blog.double-d.software/content/images/size/w1600/2024/12/2024-12-09_17-19.png 1600w, https://blog.double-d.software/content/images/2024/12/2024-12-09_17-19.png 1917w" sizes="(min-width: 720px) 720px"></figure><h2 id="using-layouts">Using layouts</h2><p>Using layouts in Laravel with Svelte sadly isn&apos;t as intuitive as using them in SvelteKit. Nevertheless, we can still use a layout-like system.</p><h3 id="creating-a-new-layout">Creating a new layout</h3><p>To accommodate our new layout file, we have to create a new directory. It can named in any way, but for the sake of clarity you should call it <code>Layouts</code>. Create it alongside the <code>Home</code> directory in <code>resources/js/Pages/</code>. In that new layout directory, create a new Svelte file called <code>App.svelte</code>, although it can be named whatever you desire.</p><p>Populate this file with your layout. Here is an example that adds a green background:</p><figure class="kg-card kg-code-card"><pre><code class="language-html">&lt;script&gt;
    let { children } = $props();
&lt;/script&gt;

&lt;main class=&quot;bg-lime-300 w-full h-full&quot;&gt;
    {@render children?.()}
&lt;/main&gt;</code></pre><figcaption><p><span style="white-space: pre-wrap;">resources/js/Pages/Layouts/App.svelte</span></p></figcaption></figure><h3 id="using-the-new-layout">Using the new layout</h3><p>To use this new layout in your <code>Index.svelte</code> file, you have to first import the layout in a script tag and then wrap your content within the layout as the following example shows:</p><pre><code class="language-html">&lt;script&gt;
    import Layout from &quot;../Layouts/App.svelte&quot;
    let { name, age } = $props();
&lt;/script&gt;

&lt;Layout&gt;
    &lt;div class=&quot;text-center font-bold text-4xl&quot;&gt;
        &lt;h1&gt;Laravel + Svelte&lt;/h1&gt;
        &lt;p class=&quot;text-2xl&quot;&gt;Hello {name} ({age})&lt;/p&gt;
    &lt;/div&gt;
&lt;/Layout&gt;</code></pre><p>Make sure your import is correct. The main page should look like this after the change (500% zoomed):</p><figure class="kg-card kg-image-card"><img src="https://blog.double-d.software/content/images/2024/12/2024-12-09_17-46.png" class="kg-image" alt="Using Laravel with Svelte" loading="lazy" width="1919" height="598" srcset="https://blog.double-d.software/content/images/size/w600/2024/12/2024-12-09_17-46.png 600w, https://blog.double-d.software/content/images/size/w1000/2024/12/2024-12-09_17-46.png 1000w, https://blog.double-d.software/content/images/size/w1600/2024/12/2024-12-09_17-46.png 1600w, https://blog.double-d.software/content/images/2024/12/2024-12-09_17-46.png 1919w" sizes="(min-width: 720px) 720px"></figure><hr><h2 id="final-words">Final words</h2><p>I hope this guide helped you in your Laravel + Svelte journey and that you now have a simple yet working website built entirely in Svelte and served by Laravel. </p><p>If you encounter any errors, check all the instructions, paths and code again. You might have missed something somewhere. If you think there is an error or something is missing, you can contact me on Discord: <a href="https://discord.gg/2kGR3AdfZH?ref=blog.double-d.software">https://discord.gg/2kGR3AdfZH</a></p><p>Don&apos;t forget to check out the GitHub repository at <a href="https://github.com/DoubleD-Software/laravel-svelte?ref=blog.double-d.software">https://github.com/DoubleD-Software/laravel-svelte</a> and give it star!</p><p>Make sure to sign up (free) for the DoubleD newsletter to receive more of these useful guides and interesting experiences below! Thank you!</p>]]></content:encoded></item></channel></rss>