<?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 Frano Šašvari on Medium]]></title>
        <description><![CDATA[Stories by Frano Šašvari on Medium]]></description>
        <link>https://medium.com/@frano.sasvari?source=rss-b5cc8ac6f2c5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2wk2p5IYwm5LhIsy5HGt4A.jpeg</url>
            <title>Stories by Frano Šašvari on Medium</title>
            <link>https://medium.com/@frano.sasvari?source=rss-b5cc8ac6f2c5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 20:30:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@frano.sasvari/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[Laravel without Facades Part 1: Routing]]></title>
            <link>https://medium.com/@frano.sasvari/laravel-without-facades-part-1-routing-a85bc0038e5f?source=rss-b5cc8ac6f2c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a85bc0038e5f</guid>
            <category><![CDATA[facade]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Frano Šašvari]]></dc:creator>
            <pubDate>Thu, 11 Apr 2019 09:04:47 GMT</pubDate>
            <atom:updated>2019-04-11T09:06:45.649Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOM2LTlgW3ctxsygYQ3iUQ.jpeg" /></figure><p>This is my second blog post about using Laravel framework without Facades. <a href="https://medium.com/@frano.sasvari/laravel-without-facades-part-0-intro-190bae09aebe">First post</a> was about explaining why not to use Facades, static classes, and helper functions. The second post is accompanied by concrete examples.</p><p>So today, I’ll show you how to use Router class and set up routes for your Laravel project.</p><p>First, we need to refactor our Route service provider:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eee1c1eaa061a95a2308d504a1acc1b2/href">https://medium.com/media/eee1c1eaa061a95a2308d504a1acc1b2/href</a></iframe><p>In RouteServiceProvider we injected <strong>Router </strong>class via dependency injection to base <strong>map()</strong> method. Later on, we can use it in mapWebRoutes() and other map() methods like mapApiRoutes(), etc.</p><p>And then we can normally define our routes in <strong>routes/web.php</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b5245eb543429d8f0a9b923a8a12c95/href">https://medium.com/media/1b5245eb543429d8f0a9b923a8a12c95/href</a></iframe><p>Basically, that’s it, we refactored RouteServiceProvider and defined all of our application routes in “routes” folder.</p><p>Thanks everyone for reading this series showing you how to use Laravel without Facades. In next post, I’ll refactor some of the built-in Middlewares in Dependency Injection way, instead of Facade usage. Stay tuned!</p><p>Previous article: <a href="https://medium.com/@frano.sasvari/laravel-without-facades-part-0-intro-190bae09aebe">Part 0: Intro</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a85bc0038e5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel without Facades Part 0: Intro]]></title>
            <link>https://medium.com/@frano.sasvari/laravel-without-facades-part-0-intro-190bae09aebe?source=rss-b5cc8ac6f2c5------2</link>
            <guid isPermaLink="false">https://medium.com/p/190bae09aebe</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Frano Šašvari]]></dc:creator>
            <pubDate>Wed, 04 Apr 2018 15:13:15 GMT</pubDate>
            <atom:updated>2019-04-11T09:27:40.008Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UwRAqao5eQB-pWktA7poRw.jpeg" /></figure><p>I like Laravel, I really do. But, I don’t like Facades, I just don’t.</p><p>In the following few posts I’ll try to explain ways of using Laravel without need of Facades.</p><p>I mean, Facades are OK for starters/learners, for smaller projects, or when you are in a hurry to make a deadline. But for mid/large size projects, when you are working in a team with other developers, Facades are not the best choice.</p><p>Why?</p><h4><strong>1. Facades </strong>behave like static classes</h4><p>First of all, Facades behave like static classes and static classes are considered as <strong>bad practice</strong> (<a href="https://r.je/static-methods-bad-practice.html">source 1</a> and <a href="https://codeburst.io/static-classes-are-evil-or-make-your-dependencies-explicit-af3e73bd29dd">source 2</a>).</p><p>Static methods and variables result in the poorly designed codebase and they try to introduce procedural code into an object-oriented world. Static variables introduce global state and static methods break encapsulation.</p><p>Also, another problem with static classes is writing tests. Testing static class in isolation is very difficult.</p><p>Explanation from <a href="https://laravel.com/docs/5.8/facades">Laravel documentation</a>:</p><blockquote>Facades provide a “static ” interface to classes that are available in the application’s service container. Laravel facades serve as “static proxies” to underlying classes in the service container…</blockquote><h4>2. Bad code readability</h4><p>Why is this important? Well, when working on a mid/large scale project with a few other team members, code readability is very important. If there are static classes (Facades) all over the place it’s just hard to read dependencies of some class or method.</p><h4>3. No autocomplete option</h4><p>In some IDEs (like NetBeans) there are no autocomplete option for Facades because they are “magically” loaded. Variables and methods are invisible to IDE.</p><p>I know that there are some packages like <a href="https://github.com/barryvdh/laravel-ide-helper">barryvdh/laravel-ide-helper</a>, but if you need to install additional packages just for autocomplete option, well, that’s just wrong.</p><h4>4. Harder to switch to other Frameworks</h4><p>As far as I know, other PHP frameworks don’t use Facades or static classes. I haven’t found any mention of “facade” or “static” keyword in other frameworks documentation: <a href="https://symfony.com/">Symfony</a>, <a href="https://cakephp.org/">CakePHP</a>, <a href="https://phalconphp.com/en/">Phalcon</a>, <a href="https://framework.zend.com/">Zend</a>, etc.</p><p>So, if you are making a switch from Laravel (with Facade usage) to any other PHP framework, it’s gonna be much harder then making a switch if you have already embraced code without Facades and static classes.</p><h4>Conclusion</h4><p>For me, Facades are bad practice and personally, I don’t like to work with them. I’m a big fan of <a href="https://www.php-fig.org/psr/">PSR</a>, because I like my code to be clean, self-explained, easy to extend, inject and use.</p><p>But, there are a few cases where Facades are “OK” to use (I use them as well) - in database migrations and seeders. It’s way easier and quicker this way, there is no need to inject anything and to waste time on something that will be run only once.</p><p>If you want to be even more consistent in your coding style, you can remove Facades from migrations and seeders too but maybe that could be just overhead.</p><p>Thanks everyone for reading this intro series showing you how to use Laravel without Facades. Next post will be about defining and using Router class and setting up the routes.</p><h4>Not Convinced?</h4><p>There are also some other articles on the Internet like this, who explain Laravel Facades and why not to use them: <a href="https://programmingarehard.com/2014/01/11/stop-using-facades.html/">source 1</a>, <a href="https://medium.freecodecamp.org/moving-away-from-magic-or-why-i-dont-want-to-use-laravel-anymore-2ce098c979bd">source 2</a>, <a href="https://www.tomasvotruba.cz/blog/2019/03/04/how-to-turn-laravel-from-static-to-dependency-injection-in-one-day/">source 3</a>.</p><h4>Useful links</h4><p>List of Facade class references on official Laravel page: <a href="https://laravel.com/docs/5.8/facades#facade-class-reference">https://laravel.com/docs/5.8/facades</a></p><p><strong>P.S.</strong> global helper functions like <a href="https://laravel.com/docs/5.6/helpers#method-app">app()</a> and <a href="https://laravel.com/docs/5.6/helpers#method-config">config()</a> are also bad practice, they are just wrapped up Facades.</p><p>Next article: <a href="https://medium.com/@frano.sasvari/laravel-without-facades-part-1-routing-a85bc0038e5f">Part 1: Routing</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=190bae09aebe" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>