<?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 Konstantin Auffinger on Medium]]></title>
        <description><![CDATA[Stories by Konstantin Auffinger on Medium]]></description>
        <link>https://medium.com/@k.auffinger?source=rss-596203152b88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4cCWSHtNtAugW4VoGHhLfg.jpeg</url>
            <title>Stories by Konstantin Auffinger on Medium</title>
            <link>https://medium.com/@k.auffinger?source=rss-596203152b88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:49:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@k.auffinger/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[npm audit fix for composer]]></title>
            <link>https://medium.com/@k.auffinger/npm-audit-fix-for-composer-4227962827a8?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/4227962827a8</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[composer]]></category>
            <category><![CDATA[package-manager]]></category>
            <category><![CDATA[supply-chain-attack]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Sun, 21 Jun 2026 15:21:31 GMT</pubDate>
            <atom:updated>2026-06-21T15:21:31.207Z</atom:updated>
            <content:encoded><![CDATA[<p>In recent weeks we had a lot of packages to update. Updates are necessary, but dangerous. Every single update can be hit by a Supply Chain Attack. Even in composer! For example, the <a href="https://www.aikido.dev/blog/supply-chain-attack-targets-laravel-lang-packages-with-credential-stealer">laravel-lang</a> package ecosystem was hit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wilozEFI1iYlQ0Vy" /></figure><p>While the NPM registry is just as susceptible to Supply Chain Attacks, npm has something cool: npm audit fix All it does is check for open vulnerabilities in your installed dependencies and then only update the ones that have one. Much better than updating all dependencies, since we’re reducing our updates to only the ones that are strictly necessary.</p><p>To my surprise, composer has composer audit but no equivalent of the fix-command. Therefore, i created it. Well, at least something close to it: composer fix</p><p>We can’t use composer audit fix , but that’s close enough for me. It does exactly what you would expect it to. Bonus: It respects filtering mechanisms like <a href="https://github.com/innobraingmbh/composer-soak-time">soak time</a>. The soak time plugin enables what min-release-age does for npm, filter packages by their age. We’re not installing the hotfix that just got released that also includes a postinstall script which harvests all our data. Not today.</p><p>Get it now via</p><pre>composer global require innobrain/composer-fix</pre><p>and see more info on the <a href="https://github.com/innobraingmbh/composer-fix">GitHub repo</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4227962827a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Livewire Only Streamed LLM Chat Interface]]></title>
            <link>https://medium.com/@k.auffinger/livewire-only-streamed-chat-interface-2296e18cbdbf?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/2296e18cbdbf</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[starter-kit]]></category>
            <category><![CDATA[laravel-starter-kit]]></category>
            <category><![CDATA[llm]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Fri, 23 May 2025 19:13:55 GMT</pubDate>
            <atom:updated>2025-06-06T07:53:53.235Z</atom:updated>
            <content:encoded><![CDATA[<p>Want to hop right into the LLM party without having to touch any JavaScript, but have it look good? And feel effortless? I do have the thing you want.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b4iU1LAcEQ-ugaUdYSKNlA.png" /><figcaption>The Chat Interface</figcaption></figure><p>Recently I have created multiple Livewire based chat interfaces for different use-cases. Be it my own projects or work. Doing so brought me to appreciate Livewire. Since <a href="https://livewire.laravel.com/docs/wire-stream">wire:stream</a> exists, we can have beautiful chat interfaces that feel right like we would have used Vue or React.</p><p>Another key ingredient in this is <a href="https://fluxui.dev/">Fluxui</a>. Since the release of the free components to power the <a href="https://laravel.com/starter-kits">Laravel Starter Kits</a> we now have great looking building blocks that make it easy to create delightful chat experiences.</p><p>Finally, my favorite way to interact with LLMs in the Laravel ecosystem: <a href="https://prismphp.com/">Prism</a>. It’s the Laravel-way of speaking to LLMs. It’s clean, it’s easy to test. And, most importantly, it has great provider interop. You want to try the new Claude Opus 4 and have been using GPT-4.1? Just get you API key and go from using(Provider::OpenAI, &#39;gpt-4.1&#39;) to using(Provider::Anthropic, &#39;opus-4&#39;). That’s it.</p><p>To celebrate the beauty of this technology, I want to share my starter kit: <a href="https://github.com/kauffinger/livewire-chat">Livewire Chat Kit</a>. It combines the three technologies to create a clean, simple way of creating chat applications. Right now, it’s only the basics that get you set up to instantly send your own first chat messages. We will build out the rest together over time. But also, it already has all the tooling you need to offer. Even dark mode!</p><p>To show you how simple it really is, here is the Chat Livewire component:</p><pre>&lt;?php<br><br>namespace App\Livewire;<br><br>use Illuminate\Support\Str;<br>use Illuminate\View\View;<br>use Livewire\Component;<br>use Prism\Prism\Enums\Provider;<br>use Prism\Prism\Prism;<br><br>class Chat extends Component<br>{<br>    public array $messages = [];<br><br>    public string $newMessage = &#39;&#39;;<br><br>    public function sendMessage(): void<br>    {<br>        if (trim($this-&gt;newMessage) === &#39;&#39;) {<br>            return;<br>        }<br><br>        $this-&gt;messages[] = new \App\Dtos\UserMessage($this-&gt;newMessage);<br>        $this-&gt;newMessage = &#39;&#39;;<br><br>        $this-&gt;js(&#39;$wire.runChatToolLoop()&#39;);<br>    }<br><br><br>    public function runChatToolLoop(): void<br>    {<br>        $generator = Prism::text()<br>            -&gt;using(Provider::OpenAI, &#39;gpt-4o-mini&#39;)<br>            -&gt;withSystemPrompt(&#39;You are a helpful assistant.&#39;)<br>            -&gt;withMessages(collect($this-&gt;messages)-&gt;map-&gt;toPrism()-&gt;all())<br>            -&gt;asStream();<br><br>        $message = &#39;&#39;;<br>        foreach ($generator as $chunk) {<br>            $message .= $chunk-&gt;text;<br><br>            $this-&gt;stream(&#39;streamed-message&#39;, Str::markdown($message), true);<br>        }<br><br>        $this-&gt;messages[] = new \App\Dtos\AssistantMessage($message);<br>    }<br><br>    public function render(): View<br>    {<br>        return view(&#39;livewire.chat&#39;);<br>    }<br>}</pre><p>That’s all there is to it. Let’s talk about some of it. The messages are DTOs, we just extend the Prism DTO and make it Wireable. This way Livewire understands how to pass it back and forth.</p><p>We have a newMessage property that holds the chat input’s value. We need this to push a new message when the user presses enter, so that we can instantly give feedback and start the stream with that new message in the chat history.</p><p>As you can see, I lied. There is JavaScript. One line. And it’s coming from a string in PHP. Kind of worse than normal JavaScript. When you think about how much it improves our UX, that becomes totally worth it. See, thanks to the $wire magic (which, come on, kind of looks like PHP) we can instantly call the runChatToolLoop method right after responding to our user. The user instantly sees their message.</p><p>We then use Prism’s generator to pass the current full string via wire:stream to the frontend as soon as the LLM spits out a token. Note how we replace the whole text and add each token to the text we send. This is because we need to wrap our text with Str::markdown, since we will render the stream in the frontend using TailwindCSS’s prose typography plugin.</p><pre>&lt;div class=&quot;relative h-full max-w-3xl mx-auto&quot;&gt;<br>    &lt;div<br>        class=&quot;flex h-[calc(100vh-10rem)] lg:h-[calc(100vh-8rem)] max-h-screen max-w-3xl mx-auto flex-1 flex-col-reverse overflow-y-scroll gap-4 py-1&quot;&gt;<br><br>        @include(&#39;livewire.loading-indicator&#39;)<br><br>        @foreach (array_reverse($messages) as $message)<br>            @if ($message instanceof \App\Dtos\UserMessage)<br>                &lt;x-chat.user-message :message=&quot;$message&quot; :index=&quot;$loop-&gt;index&quot; /&gt;<br>            @elseif($message instanceof \App\Dtos\AssistantMessage)<br>                &lt;x-chat.assistant-message :message=&quot;$message&quot; :is-first=&quot;$loop-&gt;first&quot; /&gt;<br>            @endif<br>        @endforeach<br><br>        &lt;x-chat.message-input /&gt;<br><br>    &lt;/div&gt;<br>&lt;/div&gt;</pre><p>The message components handle that. Meanwhile we render the messages array inverted so that when our container grows, we automatically scroll with it. Clean &amp; easy.</p><p>One more little trick. Let’s take a look at the ‘loading indicator’.</p><pre>&lt;div wire:loading wire:target=&quot;runChatToolLoop&quot; class=&quot;...&quot;&gt;<br>    &lt;div class=&quot;flex flex-row w-full justify-start&quot;&gt;<br>        &lt;div class=&quot;...&quot;&gt;<br>            &lt;flux:heading&gt;<br>                AI<br>            &lt;/flux:heading&gt;<br>            &lt;flux:text&gt;<br>                &lt;span class=&quot;...&quot; wire:stream=&quot;streamed-message&quot; wire:replace&gt;<br>                    &lt;span class=&quot;animate-pulse&quot;&gt;...&lt;/span&gt;<br>                &lt;/span&gt;<br>            &lt;/flux:text&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/div&gt;</pre><p>We only render the streamed message while it streams, that’s why we target runChatToolLoop.Then we just switch it out with a real message render by hiding it when the method is done. While waiting for the stream to start, we use animated dots. Everything inside the outer span will be replaced by wire stream, so the dots will be nuked right when the stream starts.</p><p>Wanna take it for a spin? Start right now by using the following:</p><pre>laravel new my-chat-app --using=kauffinger/livewire-chat-kit</pre><p>If you want to take a look at the current code, hop over <a href="https://github.com/kauffinger/livewire-chat">to the repo</a>. Feel free to open PRs!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2296e18cbdbf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lazyvim, but in PHPStorm]]></title>
            <link>https://medium.com/@k.auffinger/lazyvim-but-in-phpstorm-c6143a7eccae?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6143a7eccae</guid>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[phpstorm]]></category>
            <category><![CDATA[lazyvim]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Tue, 06 May 2025 05:22:07 GMT</pubDate>
            <atom:updated>2025-05-06T05:22:07.378Z</atom:updated>
            <content:encoded><![CDATA[<h3>LazyVim, but in PHPStorm</h3><p>Listen, I know, I know. Use Vim, it’s superior, blabla. I KNOW I SAID THAT. Ok good, now that we got that out of the way, on to other things. Unfortunately, for my Vim-brained mind, I can not hide from one simple fact.</p><p>PHPStorm is pretty good for PHP development.</p><p>I take a file, I drop it somewhere else? All namespaces aligned instantly, no sweat. I don’t have that in NVIM right now.</p><p>Inlining all instances of a constant over the whole codebase? One hotkey, done. No misses.</p><p>Good for me: I am insane, and instead of writing the NVIM plugins myself (tbh, this might be an option with today’s LLMs), I’ll just make my PHPStorm be as close as possible to my NVIM config. And, I have to say, that works. It works great. Ok, it still crashes like PHPStorm likes to do, but I can switch between both editors and not feel out of place in either.</p><p>So… How?</p><p>I use the advanced trick people who code everything themselves hate: Configuration</p><p>First, get yourself the IdeaVim and the WhichKey plugins from the marketplace:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qAwmYoJNprJe8iF64k-EUQ.png" /></figure><p>Then, download the following file to wherever you like (maybe ~/.config/idea-lazy.vim). It’s the special sauce. I found it from a guy who started configuring IdeaVim close to LazyVim defaults and took it the extra mile. Crosschecked the hotkeys and improved what I could. Find it <a href="https://github.com/kauffinger/.dotfiles/blob/master/jetbrains/.idea-lazy.vim">here</a> in my dotfiles.</p><p>Then, Import that in to your ~/.ideavimrc and configure the rest however you like:</p><pre>source ~/.idea-lazy.vim<br><br>&quot; vim settings<br>set history=1000<br><br>&quot; status bar<br>set showmode<br><br>&quot; ideavim settings (unique to IdeaVim)<br>set ideajoin<br>set ideamarks<br>set idearefactormode=normal<br>set ideastatusicon=gray<br><br>...</pre><p>And that’s all there is to it. Enjoy LazyVim-Style PHPStorm.</p><p>Also, feel free to PR anything else you find!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6143a7eccae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Livewire breaks in production for no apparent reason]]></title>
            <link>https://medium.com/@k.auffinger/livewire-breaks-in-production-for-no-apparent-reason-0ce6d1e67280?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ce6d1e67280</guid>
            <category><![CDATA[livewire]]></category>
            <category><![CDATA[bug-fixes]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Sun, 27 Apr 2025 10:23:18 GMT</pubDate>
            <atom:updated>2025-10-24T14:29:06.999Z</atom:updated>
            <content:encoded><![CDATA[<p>Your Livewire app breaks only in production. Components randomly disappear when interacting with your app. The console says e.g.</p><pre>Uncaught Snapshot missing on Livewire component with id: CrsEFA3b4wrcCYZc7I5h</pre><p>or</p><pre>Uncaught Component not found: CrsEFA3b4wrcCYZc7I5h</pre><p>The issue is php artisan optimize. Or, more specifically php artisan view:cache.</p><p>Let me explain: When using Livewire 3, Livewire by default injects so called Morph Markers. These are used by the Framework to handle disappearing HTML on updates, specifically when nesting Blade if-statements in loops or nesting components.</p><p>When the views are optimized by Laravel, they are cached without Livewire’s Morph Markers, as the Laravel Compiler will be used for compiling the views instead of Livewire’s extension of it. This makes Livewire more brittle, and will lead to the aforementioned errors. <a href="https://github.com/livewire/livewire/pull/8068">This issue exists for a good while now</a>, and I am not sure when it will be fixed. So, the current best workaround is to not cache your views in the deployment.</p><p>In your deploy script, just use php artisan optimize --except=views.</p><p>This way, Livewire’s compiler will run over the view when it is compiled, and you benefit of the power of the Morph Markers (and of the good feeling of your app not being broken).</p><p>If you want to learn more, make sure to check out the <a href="https://github.com/livewire/livewire/pull/8068">issue on GitHub</a>.</p><p>UPDATE: The fix is <a href="https://github.com/livewire/livewire/releases/tag/v3.7.0-beta.1">merged</a>! As of now, only in a beta release. But expect a release at wire:live!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ce6d1e67280" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PHP Codemap for Repo Prompt]]></title>
            <link>https://medium.com/@k.auffinger/php-codemap-for-repo-prompt-e0152fc2b926?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0152fc2b926</guid>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[agents]]></category>
            <category><![CDATA[repo-prompt]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Thu, 27 Feb 2025 20:00:21 GMT</pubDate>
            <atom:updated>2025-02-27T20:00:21.548Z</atom:updated>
            <content:encoded><![CDATA[<p>Want to compress your PHP code like you can with swift and js? I wanted that too, and now we both can do it!</p><p>php-codemap is a Composer package that generates a textual overview — a “codemap” — of your PHP code, listing out classes, methods, and public properties. Now you can even push large codebases as context to any chat interface (or API, if that’s what you prefer).</p><p>In this post, I’ll walk you through how to set up and use `php-codemap`. Let’s get started.</p><h4>Setting Up php-codemap</h4><p>First things first, you need to get `php-codemap` into your project. It’s a simple one-liner with Composer:</p><pre>composer require kauffinger/php-codemap</pre><p>This pulls the package and its dependencies into your project, and you’ll find the codemapcommand waiting for you in vendor/bin. Make sure you’re running PHP 8.3 or higher — older versions aren’t supported.</p><h4>Configuring Codemap</h4><p>Now that we’ve got the skeleton in place, let’s configure the package to fit your project. By default, it scans your src directory, but you’ll want to tailor this to your actual codebase. The easiest way? Drop a codemap.php file in your project root (it also gets generated automatically). Here’s an example:</p><pre><br>&lt;?php<br>use Kauffinger\Codemap\Config\CodemapConfig;<br>use Kauffinger\Codemap\Enum\PhpVersion;<br><br>return CodemapConfig::configure()<br>    -&gt;withScanPaths([&#39;app/Models&#39;, &#39;app/Services&#39;])<br>    -&gt;withPhpVersion(PhpVersion::PHP_8_3);</pre><h4>Generating a Codemap</h4><p>With everything installed and configured, it’s time to put `php-codemap` to work. Run this in your terminal:</p><pre>./vendor/bin/codemap</pre><p>Boom — you’ll get a codemap.txt file in your project root, filled with a neat overview of your code. Want to scan specific spots instead of the config defaults? Just throw them in:</p><pre>./vendor/bin/codemap app/Http tests/Unit</pre><p>Need the output somewhere else?</p><pre>./vendor/bin/codemap — output=docs/my-codemap.txt</pre><p>Or pipe it to stdout if you want to use it in a script easily:</p><pre>./vendor/bin/codemap — output=-</pre><p>If your project’s running an older PHP version, specify it like this:</p><pre>./vendor/bin/codemap — php-version=8.1</pre><p>This keeps the parser in sync with your code. The result? A clean text file like this:</p><pre><br>File: app/Models/User.php<br> Class: App\Models\User<br> public function posts(): HasMany<br><br>File: app/Services/AuthService.php<br> Class: App\Services\AuthService<br> public function login(array $credentials): bool</pre><p>It’s all there — files, classes, methods, and public properties — laid out for easy reading.</p><h4>Going Further with Advanced Usage</h4><p>For bigger projects, you might want to tighten up what gets scanned. Exclusion patterns aren’t a thing yet, but you can keep it lean by listing only what matters in your codemap.php:</p><pre>return CodemapConfig::configure()<br> -&gt;withScanPaths([‘app/Models’, ‘app/Services’]);</pre><p>This skips the noise and focuses on the core. It’s a small tweak that makes a big difference when your codebase starts sprawling.</p><h4>Wrapping Up</h4><p>Give it a spin. You API bill will like it. Check it out on [GitHub](<a href="https://github.com/kauffinger/php-codemap">https://github.com/kauffinger/php-codemap</a>) or grab it from [Packagist](<a href="https://packagist.org/packages/kauffinger/php-codemap">https://packagist.org/packages/kauffinger/php-codemap</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0152fc2b926" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Jobs increase attempts for no apparent reason]]></title>
            <link>https://medium.com/@k.auffinger/laravel-jobs-increase-attempts-for-no-apparent-reason-41db659e3901?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/41db659e3901</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[laravel-queue]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Tue, 25 Feb 2025 20:30:47 GMT</pubDate>
            <atom:updated>2025-02-25T20:30:47.036Z</atom:updated>
            <content:encoded><![CDATA[<p>When running a queue with multiple workers and any of the jobs or the queue itself sets a timeout of more than 90 seconds, I can tell you why…</p><p>It might look like it’s a memory overflow, but it is most probably not. When you reduce your workers to only one, does the queue work normally again? If the answer is yes, retry_after for the queue connection is set to a value that is less than timeout.</p><p>So, the fix is quite straightforward. Go into config/queue.php and find the queue connection you use. For the sake of this article, let’s assume it’s the database driver and you execute your workers by running the following command:</p><pre>php artisan queue:work --queue=default --timeout=800</pre><p>So, you need to change the following setting:</p><pre>&#39;connections&#39; =&gt; [<br>    &#39;database&#39; =&gt; [<br>        &#39;driver&#39; =&gt; &#39;database&#39;,<br>        &#39;connection&#39; =&gt; env(&#39;DB_QUEUE_CONNECTION&#39;),<br>        &#39;table&#39; =&gt; env(&#39;DB_QUEUE_TABLE&#39;, &#39;jobs&#39;),<br>        &#39;queue&#39; =&gt; env(&#39;DB_QUEUE&#39;, &#39;default&#39;),<br>        /*<br>        * Due to the --timeout=800 setting, we need to increase<br>        * retry_after to over 800 seconds, too.<br>        */<br>        &#39;retry_after&#39; =&gt; (int) env(&#39;DB_QUEUE_RETRY_AFTER&#39;, 810),<br>        &#39;after_commit&#39; =&gt; false,<br>    ],<br>],</pre><p>This will make your queue work correctly again. This is because workers, when looking at the jobs available, are checking the reserved_at column. If a job is reserved, they won’t execute it. But if reserved_at was more than retry_after seconds ago, the worker will pick it up anyways. This ensures jobs are executed again, if a memory leak indeed did occur. Then the worker would not have been able to release the job back on the queue, and it would be stuck forever.</p><p>Therefore: <strong>Remember to always increase </strong><strong>retry_after to at least the highest value of </strong><strong>timeout you use for your queue connection</strong>.</p><p>Thanks to <a href="https://themsaid.com/laravel-queues-in-action">https://themsaid.com/laravel-queues-in-action</a> which is where I found the answer to my issues. If you think you could benefit from understanding Laravel queues better, I wholeheartedly recommend you buy the eBook. It’s worth every cent.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41db659e3901" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Repo_ignore Rules for Laravel]]></title>
            <link>https://medium.com/@k.auffinger/repo-ignore-rules-for-laravel-2f5d33a1f2db?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f5d33a1f2db</guid>
            <category><![CDATA[o1-pro-mode]]></category>
            <category><![CDATA[repo-prompt]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Tue, 21 Jan 2025 06:17:25 GMT</pubDate>
            <atom:updated>2025-04-10T10:07:23.862Z</atom:updated>
            <content:encoded><![CDATA[<p>When using <a href="https://repoprompt.com/">Repo Prompt</a> to harness the power of o1 pro mode in code, it’s annoying to have to exclude folders excluding large files. Often, those files don’t contribute to better model performance when they are not relevant to the task itself. The base .repo_ignore file works, but there is some essential lines missing to work out of the box with Laravel projects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UauaZx06weOP4RZ79vawIg.png" /><figcaption>Repo Prompt</figcaption></figure><p>The following is the base .repo_ignore extended with relevant additions for laravel projects.</p><pre># Package manager caches<br>**/node_modules/<br>**/.npm/<br>**/__pycache__/<br>**/.pytest_cache/<br>**/.mypy_cache/<br>**/vendor/<br><br># Build caches<br>**/.gradle/<br>**/.nuget/<br>**/.cargo/<br>**/.stack-work/<br>**/.ccache/<br>**/storage/framework<br>**/bootstrap/cache<br><br># IDE and Editor caches<br>**/.idea/<br>**/.vscode/<br>**/*.swp<br>**/*~<br>**/_ide_helper.php<br>**/storage/debugbar<br><br># Temp files<br>**/*.tmp<br>**/*.temp<br>**/*.bak<br><br>**/*.meta<br>**/package-lock.json<br>**/composer.lock<br>**/auth.json<br><br># Other unnecessary stuff<br>**/artisan<br><br># SQLITE Database<br>**/database/database.sqlite*<br><br><br># Optional further ignore patterns<br>**/storage/app/<br>**/storage/logs/<br><br># filament<br>public/js/filament/**<br>public/css/filament/**</pre><p>The first block now includes the vendor folder. We exclude laravel caches like storage/framework and bootstrap/cache. The composer.lock file can be a lot of tokens, so we exclude it as well. Also, let’s remove auth.json so we do not accidentally send that to OpenAI. Finally, two optional settings: storage/app and storage/logs. These can be useful under some circumstances, but chances are you won’t need them.</p><p>With this, you should have significantly reduced your input tokens and are ready to prompt!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f5d33a1f2db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Don’t Cascade your Deletes]]></title>
            <link>https://medium.com/@k.auffinger/dont-cascade-your-deletes-2fb71e71f6d2?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fb71e71f6d2</guid>
            <category><![CDATA[database-administration]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Mon, 20 Jan 2025 19:03:35 GMT</pubDate>
            <atom:updated>2025-01-20T19:03:35.698Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I’ve seen <a href="https://www.youtube.com/watch?v=OZGbySrPhX0">a stream</a> by Nuno Maduro in which he explained that he does not use cascading deletes at all. That’s cazytalk to someone who was taught the opposite by anything I’ve consumed to this day. But listen, he’s right.</p><p>Remember TailwindCSS and why it’s great? You define your CSS right next to the structure that it belongs to. The behavior, look and elements are colocated. Right next to each other. Now let’s think of application code and databases again. You define your cascading deletes in the migration. At the point of designing your data model, you decide about it’s deletion behavior. That’s ok while iterating early on, but I’ve seen migration folders with 200 files in them, 90% of them being changes to existing tables. I do not like to think of those moments. I don’t want to read through migrations (or migrate a server and look at the database) to understand what is going to happen in an application when I delete something. That makes no sense to me.</p><p>The crazy thing is that IT DID until a few minutes ago.</p><p>Here is how things make sense: Cascades? No. Constraints? Yes. By enforcing the constraints, developers will have to explicitly handle the deletion (or creation) in the correct order. The code about what happens in the database will be wonderfully colocated to the place where the logic happens. Right were it belongs. Explicitly. The database will be a joyful pain in the ass until you did what is defined to happen by the data model.</p><p>This concept transfers to other parts of your migration as well. No class coupling like foreignIdFor(User::class) or using default values. Nothing but the raw data model. When you rename a class, your migrations should not break. When your default subscription plan changes, you should not have to create a new migration (at least if you use a string as the datatype).</p><p>I like how this makes everything explicit in code. Easier code reviews, less time spent understanding what happens.</p><p>While I’ve seen some disagreement in the comments, I do think that this philosophy of decoupling behavior will prevail. It’s not only better for humans but also for Language Models. No need to infer database behavior on the basis of a series of migration files. Instead: Multiple examples of what has to happen if a model is deleted. Default value? Set by enum ValueEnum::SomeValue, perfect.</p><p>What are your best arguments against the approach? I’d like to hear your thoughts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fb71e71f6d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The only correct way to use Laravel Pint in PHPStorm]]></title>
            <link>https://medium.com/@k.auffinger/the-only-correct-way-to-use-laravel-pint-in-phpstorm-0ccec9ae2160?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/0ccec9ae2160</guid>
            <category><![CDATA[phpstorm]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[code]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Mon, 06 Jan 2025 20:26:13 GMT</pubDate>
            <atom:updated>2025-01-06T20:26:13.621Z</atom:updated>
            <content:encoded><![CDATA[<p>Unfortunately, it’s not directly obvious how you should use Pint in PHPStorm in the most PHPStorm-agnostic way. But having to deal with different Pint versions and configs when working in a team is a nightmare. Especially when you are onboarding new developers.</p><p>Some of you may have read my previous article about <a href="https://medium.com/@k.auffinger/mechanically-sustaining-code-quality-in-laravel-applications-90dd8439ca5f">mechanically sustaining code quality in laravel applications</a>. I NEED Pint to work for anyone, otherwise I’ll have to enforce it in CI, create commits and push them back to the remote. That works, but people new to working in teams will hate it. The integrated PHPStorm version unfortunately needs to be configured for everyone, and theoretically for each project. But no one working in Laravel needs that. We have Pint already, and we also have our own config if we ever were to not use the defaults. So here is the way to go:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JMOWNI7ZrZ9Y7DZeSqIHhw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7bbOs8UUxkhED-HxHHSadA.png" /></figure><p>The first setting will enable inspections and the second will set Pint as an “External Formatter”. This way your local Pint project installation and it’s corresponding pint.json config will be used.</p><p>Finally, make sure you have Reformat Code active on Save if you ever disabled it for a File Watcher like I had:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xj2nNacinA4VfKYwwKLrdg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0ccec9ae2160" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mechanically sustaining Code Quality in Laravel Applications]]></title>
            <link>https://medium.com/@k.auffinger/mechanically-sustaining-code-quality-in-laravel-applications-90dd8439ca5f?source=rss-596203152b88------2</link>
            <guid isPermaLink="false">https://medium.com/p/90dd8439ca5f</guid>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Konstantin Auffinger]]></dc:creator>
            <pubDate>Thu, 05 Dec 2024 21:25:38 GMT</pubDate>
            <atom:updated>2025-03-17T20:07:21.564Z</atom:updated>
            <content:encoded><![CDATA[<p>Whenever you build something someone else might have to touch in the future, that is, any time you write code to build a business, you want to make it as easy as possible for that someone else to do the things they need to make your business stay alive.</p><p>In the Laravel ecosystem, there is a lot of people who have embraced the Laravel conventions. And, just as important, code writing machines have adopted those conventions as well. (I am cryptically talking about LLMs here.)</p><p>In this article I will show you my favorite toolkit to make sure I stay close to the conventions while maximizing robust code.</p><p>Let’s setup a Laravel application:</p><pre>laravel new example-app</pre><figure><img alt="Laravel Installer" src="https://cdn-images-1.medium.com/max/535/1*0zJhEeCwTfBnNeZreaSrKw.png" /></figure><p>Choose Breeze if you need authentication. It’s a minimal starting point for auth, and anything you might need later can be added easily.</p><figure><img alt="Select Pest as your test runner" src="https://cdn-images-1.medium.com/max/535/1*of9I2VYoKu1PUNc-DjfEwg.png" /></figure><p>In this installation, make sure to choose Pest as your test runner. Note that I say “test runner” not testing framework. Under the hood Pest uses PHPUnit. But it’s integration with Laravel is much better.</p><h3>Automated Quality</h3><p>Now that we have our skeleton, let me tell you the things I always add first: Pint is an opinionated formatter used by Laravel itself. For efficiently working together, code style is essential. To maximize the number of people who can read our code, we want to stay close. But, there is a few things I like to add. The following is my pint.json. All you</p><pre>{<br>    &quot;preset&quot;: &quot;laravel&quot;,<br>    &quot;rules&quot;: {<br>        &quot;array_push&quot;: true,<br>        &quot;backtick_to_shell_exec&quot;: true,<br>        &quot;date_time_immutable&quot;: true,<br>        &quot;declare_strict_types&quot;: true,<br>        &quot;lowercase_keywords&quot;: true,<br>        &quot;lowercase_static_reference&quot;: true,<br>        &quot;fully_qualified_strict_types&quot;: true,<br>        &quot;global_namespace_import&quot;: {<br>            &quot;import_classes&quot;: true,<br>            &quot;import_constants&quot;: true,<br>            &quot;import_functions&quot;: true<br>        },<br>        &quot;mb_str_functions&quot;: true,<br>        &quot;modernize_types_casting&quot;: true,<br>        &quot;no_superfluous_elseif&quot;: true,<br>        &quot;no_useless_else&quot;: true,<br>        &quot;no_multiple_statements_per_line&quot;: true,<br>        &quot;ordered_class_elements&quot;: {<br>            &quot;order&quot;: [<br>                &quot;use_trait&quot;,<br>                &quot;case&quot;,<br>                &quot;constant&quot;,<br>                &quot;constant_public&quot;,<br>                &quot;constant_protected&quot;,<br>                &quot;constant_private&quot;,<br>                &quot;property_public&quot;,<br>                &quot;property_protected&quot;,<br>                &quot;property_private&quot;,<br>                &quot;construct&quot;,<br>                &quot;destruct&quot;,<br>                &quot;magic&quot;,<br>                &quot;phpunit&quot;<br>            ],<br>            &quot;sort_algorithm&quot;: &quot;none&quot;<br>        },<br>        &quot;ordered_interfaces&quot;: true,<br>        &quot;ordered_traits&quot;: true,<br>        &quot;protected_to_private&quot;: true,<br>        &quot;self_accessor&quot;: true,<br>        &quot;self_static_accessor&quot;: true,<br>        &quot;strict_comparison&quot;: true,<br>        &quot;visibility_required&quot;: true<br>    }<br>}</pre><p>This is heavily inspired by Nuno Maduro’s <a href="https://github.com/nunomaduro/pint-strict-preset">strict pint preset</a>, but with a few changes to not be as interfering. For example, I remove the method ordering, as I like the Livewire convention of keeping your render function at the very bottom of the class. The preset will enforce strict types, which is a great way to prevent hard to debug issues. It will also order non method class members, which helps being consistent.</p><p>Next in formatting: Your Blade files. My toolset of choice are blade-formatter &amp; rustywind. Both available via npm:</p><pre>npm install --save-dev blade-formatter</pre><pre>npm install --save-dev rustywind</pre><p>Set them both up in your package.json:</p><pre>&quot;scripts&quot;: {<br>    &quot;build&quot;: &quot;vite build&quot;,<br>    &quot;dev&quot;: &quot;vite&quot;,<br>    &quot;format&quot;: &quot;blade-formatter \&quot;./resources/**/*.blade.php\&quot; -w &amp;&amp; rustywind --write .&quot;,<br>    &quot;format:check&quot;: &quot;blade-formatter \&quot;./resources/**/*.blade.php\&quot; --check-formatted --diff &amp;&amp; rustywind --check-formatted .&quot;<br>}</pre><p>Now you can run npm run format and have your blade files formatted and your tailwind classes sorted at the same time.</p><p>For even more efficiency, let’s go one step further and set up a composer script in composer.json:</p><pre>&quot;scripts&quot;: {<br>    ...<br>    &quot;format&quot;: [<br>        &quot;vendor/bin/pint&quot;,<br>        &quot;npm run format&quot;<br>    ],<br>    &quot;format:check&quot;: [<br>        &quot;vendor/bin/pint --test&quot;,<br>        &quot;npm run format:check&quot;<br>    ]<br>}</pre><p>Now all your code gets formatted to Laravel &amp; Tailwind standard code with one composer format. Nice. Additionally, you can use composer format:check in your CI to make sure the standards are adhered to.</p><p>But not all code style issues are solved by formatting. There is more to be automated. Rector is the next tool in our tools that will make sure we have to do less of the grunt work of keeping our code in shape.</p><pre>composer require rector/rector --dev</pre><p>Rector is a tool for automated code refactoring. You give it rules, it gives you code. Sounds easy enough. Let’s first add it’s Laravel extension:</p><pre>composer require --dev driftingly/rector-laravel</pre><p>Now, add a rector.php to your application root. The following is my essential configuration. The Laravel set list is self-explanatory. The withPhpSets() makes sure you use the latest php features up to the php version configured in your composer.json.</p><pre>&lt;?php<br><br>declare(strict_types=1);<br><br>use Rector\Config\RectorConfig;<br><br>return RectorConfig::configure()<br>    -&gt;withPaths([<br>        __DIR__.&#39;/app&#39;,<br>        __DIR__.&#39;/bootstrap&#39;,<br>        __DIR__.&#39;/config&#39;,<br>        __DIR__.&#39;/lang&#39;,<br>        __DIR__.&#39;/public&#39;,<br>        __DIR__.&#39;/resources&#39;,<br>        __DIR__.&#39;/routes&#39;,<br>        __DIR__.&#39;/tests&#39;,<br>    ])<br>    -&gt;withPhpSets()<br>    -&gt;withPreparedSets(<br>        deadCode: true,<br>        codeQuality: true,<br>        earlyReturn: true,<br>    )<br>    -&gt;withSets([<br>        \RectorLaravel\Set\LaravelLevelSetList::UP_TO_LARAVEL_110,<br>        \RectorLaravel\Set\LaravelSetList::LARAVEL_CODE_QUALITY,<br>        \RectorLaravel\Set\LaravelSetList::LARAVEL_IF_HELPERS,<br>        \RectorLaravel\Set\LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES,<br>        \RectorLaravel\Set\LaravelSetList::LARAVEL_COLLECTION,<br>        \RectorLaravel\Set\LaravelSetList::LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL,<br>        \RectorLaravel\Set\LaravelSetList::LARAVEL_ARRAYACCESS_TO_METHOD_CALL,<br>        \RectorLaravel\Set\LaravelSetList::LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME,<br>    ]);</pre><p>Now, back in the composer.json make sure to have the correct php version and add the following to the scripts section:</p><pre>&quot;rector&quot;: [<br>    &quot;vendor/bin/rector&quot;,<br>    &quot;vendor/bin/pint&quot;<br>],</pre><p>composer rector will now execute rector, and then pint. Rector does not do any code formatting, but transformations on your AST (abstract syntax tree), which means it really does not care about how your code looks. A little pint right after fixes that.</p><h3>Less automated Quality</h3><p>Additional code security, but not as automated can be gained with larastan. Larastan is an extension for phpstan, making it compatible with laravel.</p><pre>composer require --dev &quot;larastan/larastan:^3.0&quot;</pre><p>Add the following config to phpstan.neon in your application root:</p><pre>includes:<br>    - vendor/larastan/larastan/extension.neon<br>    - phar://phpstan.phar/conf/bleedingEdge.neon<br><br>parameters:<br>    paths:<br>        - app/<br><br>    level: 5</pre><p>Level 5 is sensible, and the bleeding edge config will ensure you receive breaking changes in analysis immediately. This is ok, as this is only a static analyzer. It won’t break as a dependency, it will only fail your CI. And that’s good, as it will have failed because of a potential error in your code.</p><p>Let’s add a script again for easy execution, with some extra memory (otherwise you will most likely run out on any decent size project):</p><pre>&quot;analyse&quot;: [<br>    &quot;vendor/bin/phpstan analyse --memory-limit=2G&quot;,<br>],</pre><p>Now you can let your code be analysed — but you will have to fix the issues yourself. Still, that’s a good trade to make.</p><p>One last thing: Remember when I told you to use Pest? We can squeeze out a little more automatic code security. Pest now has <a href="https://pestphp.com/docs/arch-testing">architecture testing</a>. To use it, add ArchTest.php in your tests/Feature folder. That’s not exatly where I would put it, but this way you don’t have to fiddle with the phpunit.xml. If you are familiar with that, you probably have your own preference where to put it.</p><pre>&lt;?php<br><br>arch(&#39;it fulfills security preset&#39;)<br>    -&gt;preset()-&gt;security();<br><br>arch(&#39;it fulfills php preset&#39;)<br>    -&gt;preset()-&gt;php();<br><br>arch(&#39;it does not use debugging&#39;)<br>    -&gt;expect([&#39;dd&#39;, &#39;dump&#39;, &#39;ddd&#39;, &#39;ray&#39;])<br>    -&gt;not<br>    -&gt;toBeUsed();</pre><p>This test will make sure you fulfill best practices regarding functions that are still in php, but probably should not be used when using Laravel. And, additionally, no debugging functions in your code. Nice. It’ll even show you the line where something disallowed is exactly. Let’s help us execute that.</p><pre>&quot;test&quot;: [<br>    &quot;vendor/bin/pest --parallel&quot;<br>],</pre><p>Running Pest in parallel will significantly speed up our tests (and enable the much preferred compact output of Pest). Enjoy your fast &amp; helpful test suite!</p><p>For now, that’s all. I’ll update whenever I find something else that helps me save time improving the code quality.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90dd8439ca5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>