<?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 Deric Cain on Medium]]></title>
        <description><![CDATA[Stories by Deric Cain on Medium]]></description>
        <link>https://medium.com/@dericcain?source=rss-36e8ac24d38c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7cTgsS3eCvwHyph9.</url>
            <title>Stories by Deric Cain on Medium</title>
            <link>https://medium.com/@dericcain?source=rss-36e8ac24d38c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 11:02:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dericcain/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[7 ways for the beginner programmer to become better, faster]]></title>
            <link>https://medium.com/laravel-ramblings/7-ways-for-beginner-programmers-to-become-better-faster-22518339541c?source=rss-36e8ac24d38c------2</link>
            <guid isPermaLink="false">https://medium.com/p/22518339541c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Deric Cain]]></dc:creator>
            <pubDate>Mon, 05 Jun 2017 02:12:50 GMT</pubDate>
            <atom:updated>2017-06-05T12:49:58.860Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*Y4F9muGh6m9RBoN7-qepNw.jpeg" /></figure><p>I know what it’s like to be a beginner in software development. I remember having no idea what I was doing (and still don’t sometimes 😃) and it took all the effort I had just to end up with some #basic code that performed the simplest of tasks. I spent countless hours debugging small issues that I was sure I would never figure out, all the while wondering why I was even bothering learning web development since I, obviously, was not that good at it.</p><p>And then one day, things started to make sense. I started understanding how things worked and could build meaningful apps. It’s as if something had clicked and I suddenly understood “programming”. The path to that place took some time, but reflecting back on those days, there were definitely some things that helped me progress a lot faster than others, and I am going to share those things with you. Here are 7 things that will help you as a beginner programmer transition into a more seasoned programmer.</p><h3>1. Build things</h3><p>Yeah, I know. This seems kinda obvious, but it’s true. Build as many “throw away” apps as possible. I mainly use Laravel and I am always creating new projects just to test stuff out. Figuring out what Object Oriented Programming is? Create a small project, quickly, that allows you to practice what you are learning.</p><p>I have my local environment set up so that it is easy for me to start a new project. You should take some time to make sure you local environment allows you to start projects quickly. When you are starting out, don’t let all of the bells and whistles of Docker vs Vagrant vs “who knows what” get in your way. If it takes using MAMP or WAMP just so you can start a project quickly, do that. Spend more time writing code than fixing your local environment.</p><p>When you start building things, make sure you are building things that integrate with API’s. You will learn a ton working with the different API’s out there. Check out the big tech players’ API’s like Facebook, Twitter, Github and Google. Lot’s of companies use those API’s and it will only benefit you to play around with them.</p><p>Above all, just build things. To-do apps, messenger apps, forums, blogs, anything and everything. Just build. Run into a road block and can’t think of something to build? Go here.</p><h3>2. Just finish</h3><p>Speaking of building things, you should get into a good habit of always finishing what you build. This will be one of your greatest habits. Because, one day, you may want to build a real product, and everything will get in your way and try to keep you from finishing. Got kids? Got a significant other? A job? Are you breathing? If you said “yes” to any of those, you will struggle to finish what you start. So, start now and build the healthy habit of finishing. See projects through to their completion. Also, this will give you a nice portfolio when it comes time to look for a job.</p><h3>3. Code dive (no equipment necessary 🌊)</h3><p>What is code diving? It’s when you look at source code and try and figure out what it does. I will choose a module in Laravel and I will look at all of the code for that module and try and figure out what is going one. There are tons of advanced techniques used in the Laravel framework and they will bring about many questions when you see them. When you run into a piece of code that you don’t understand, Google it and figure out what it does. If you can’t find an answer, use StackOverflow, or better yet, <a href="https://laracasts.com/">Laracasts</a>. There are tons of great people in the Laravel community just waiting to help you!</p><p>If you’re not a Laravel developer, no worries! Just search for the most popular framework or library that is in your language (as long as it’s open source), and start code diving.</p><p>This is literally one of the things that helped me the most in becoming a better developer. One of the main reasons it has helped is because when I run into an issue, instead of running to Stack Overflow immediately, I don’t mind diving into the source code to figure out what is going on. This gives a true understanding of the code that is being used and will help tremendously in becoming a better developer,</p><h3>4. Explore other languages</h3><p>One of the things that made me a better developer was looking at other languages. I was always intrigued by Rails, so I decided to check out Ruby. I spent quite a few weeks learning some of the language and it really taught me a lot about PHP, believe it or not. It forced me to think outside of how I normally think when using my day-to-day language.</p><p>Now, if you are very new to software development, be careful with this one. Be sure a get a fairly good understanding of your main language first. You don’t want to try and take on too much at once, because that could actually be counter productive. Gather a good foundation of your chosen language and then think about exploring other languages.</p><h3>5. Just getting things working isn’t enough</h3><p>I remember the days of, “If I can just get this to work…”. I would spend a lot of time just trying to get something to work and then neglect the fact that once I got it to work, it needed to be refactored. Or, maybe there was a better way to solve the problem that provided a cleaner solution.</p><p>Whenever you solve a problem, I would challenge you to look at your solution and give a little more thought into how you can make it better. Can you clean it up a little by refactoring some extra methods out of it? Does it need to be extracted so that you can reuse it? Are your variables and methods named so well that they describe exactly what they are doing? Does it need comments because it’s a specific edge case that other developers may need to know about?</p><p>Take the extra step to make it better even after you’ve spent x amount of hours just trying to get it to work.</p><h3>6. Test your code</h3><p>Test. Your. Code. At least learn about testing. I had no idea what a test was until I had been programming for about a year and a half. When I was learning some Ruby, the tool that I was using to learn ran tests on the exercises that I was performing. I was intrigued by the notion that there was some code that tested my code. It didn’t take long for me to gain an interest in testing, and then, of course Test Driven Development, but I digress…</p><p>If you want to progress to the next level, learn about testing and learn how you can incrementally adopt testing with the code that you are writing. Not only will it help you gain confidence in the code that you have written, it will force you to write testable code, which will, in turn, make you a better developer.</p><h3>7. Help others</h3><p>This is part of the process. Find someone that wants to learn and pass on as much knowledge as you have and help them grow. You would be amazed at how much it helps you learn just by helping others.</p><p>But, more importantly, help because it’s what we, as developers, do. Have you thought about that? How many developers out there maintain their own open source projects that others benefit from? They are constantly resolving issues, updating their code bases, and most of them do it for nothing. Not. A. Penny.</p><p>Oh, and have you ever posted anything on Stack Overflow? There are hundreds, if not thousands, of developers there just waiting to help you solve a problem you may have. All for nothing.</p><p>Basically, you should give back to a community that has given so much to help you.</p><h3>Conclusion</h3><p>Learning to code is like anything else in life (but way better)… You will get out exactly what you put in. Spend a lot of time writing code and use these 7 ideas to help guide you in becoming a better developer. Write lots of code and be patient. Things will start to make sense and then one day, you won’t be a beginner any more.</p><p>What helped you become a better developer when you started? I would love hear what helped you most.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22518339541c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/laravel-ramblings/7-ways-for-beginner-programmers-to-become-better-faster-22518339541c">7 ways for the beginner programmer to become better, faster</a> was originally published in <a href="https://medium.com/laravel-ramblings">Geek Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Easy site management with EasyEngine]]></title>
            <link>https://medium.com/laravel-ramblings/easy-site-management-with-easyengine-7295708cc6ad?source=rss-36e8ac24d38c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7295708cc6ad</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[digitalocean]]></category>
            <category><![CDATA[linode]]></category>
            <category><![CDATA[web-hosting]]></category>
            <category><![CDATA[lets-encrypt]]></category>
            <dc:creator><![CDATA[Deric Cain]]></dc:creator>
            <pubDate>Sat, 21 Jan 2017 04:02:07 GMT</pubDate>
            <atom:updated>2017-02-27T23:12:10.500Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have ever had to set up and manage websites on a VPS, you should really check out <a href="https://easyengine.io/">EasyEngine</a>. It will make your life approximately 1,000% easier. Let’s look at a scenario. I have a new Linode or Digital Ocean instance setup, installation is as easy as entering this command: wget -qO ee rt.cx/ee &amp;&amp; sudo bash ee.</p><p>Once that is finished, all you will do to create a site is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3aba85c12b6e5a3a8ce9b13b7324ab97/href">https://medium.com/media/3aba85c12b6e5a3a8ce9b13b7324ab97/href</a></iframe><p>You now have a fresh install of Wordpress running on Nginx. Simple.</p><p>Here are a few of my favorite things about EasyEngine.</p><h3>Wordpress Install</h3><p>Now, I would challenge you to look more into their different commands. For instance, if you want to create a Wordpress site and configure it for the W3 Total Cache plugin so that your site is crazy fast. All you have to do is enter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96af016240de17b5fc60ccd38e471ca8/href">https://medium.com/media/96af016240de17b5fc60ccd38e471ca8/href</a></iframe><p>It will automatically set up the server with the correct caching settings for the W3 Total Cache plugin. You don’t have to worry about messing with Nginx config files, or configuring the servers cache — it is all configured and ready to go.</p><p>What about Wordpress multisite? Here you go:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/512b52f88da56d04d3da631b488dc652/href">https://medium.com/media/512b52f88da56d04d3da631b488dc652/href</a></iframe><p>or</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4874368ff1f3f4066c5d498995d26d77/href">https://medium.com/media/4874368ff1f3f4066c5d498995d26d77/href</a></iframe><p>It really is so simple to use and it always works.</p><h3>Organization</h3><p>One of my favorite aspects of the EasyEngine tool is the organization that it provides. I have a few servers that I manage and they all use EasyEngine. No matter what server I am on, I know that all of my sites are organized neatly in the /var/www/. It doesn&#39;t choose some user folder to put them in like, say... Server Pilot (which also costs money to do anything significant). This means that I can go to my www folder and type ls -l and see all of the sites that reside on that server. Of course, I could just use the EasyEngine shortcut of ee site list and have a nicely printed out list of all of the current sites. Again, so simple.</p><h3>Nginx Config, if you have to…</h3><p>Sometimes you may find that you have to edit Nginx conf files. It seems that I can never remember the path to the available-sites folder on the system. This means that I have to either google it or I will look in every single folder until I find the right path (yes, I should probably learn grep but I just haven&#39;t taken the time yet). This is so easy with EasyEngine. Ready? ee site edit example.com Yep. That&#39;s it.</p><h3>Letsencrypt (Can you say free SSL/TLS certificate?)</h3><p>I have been very intrigued by the <a href="https://letsencrypt.org/">Letsencrypt</a> open source initiative. I would love to have a free SSL certificate! While Letsencrypt is still in beta, they are moving fast to produce just that — free site encryption using SSL/TLS. EasyEngine is moving fast and has already implemented support for Letsencrypt.</p><p>Now, there is a caveat to Letsencrypt and that is the certificate age. A single certificate will only last 90 days and then a new one must be obtained. This would require some server commands in order to make this happen. This is not a huge deal, but I don’t want to have to set a 90-day reminder to remind me to log in to my server and re-install another certificate. This would be a huge nightmare if you had quite a few sites.</p><p>EasyEngine to the rescue! Once I updated my current sites with ee site update example.com --letsencrypt, EasyEngine creates a cron job that will automatically update the sites SSL every 90 days. That is just too sweet.</p><h4>Side note</h4><p>If you use the --letsencrypt switch on one of your sites, be sure and set an DNS A record for www and non-www of that site. Even if you are setting up on a subdomain, you need to do this. Hopefully, this saves someone some headache.</p><h3>Closing</h3><p>EasyEngine really is a timesaver. I know some server management, but that is mostly on the Microsoft side, so learning to be a DevOps is not a high priority on my list. If you, too, want to save some time on setting up and managing sites, I highly recommend giving EasyEngine a shot. Let me know if you have any questions or comments! You can find me on Twitter at <a href="http://twitter.com/dericcain">@dericcain</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7295708cc6ad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/laravel-ramblings/easy-site-management-with-easyengine-7295708cc6ad">Easy site management with EasyEngine</a> was originally published in <a href="https://medium.com/laravel-ramblings">Geek Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple example of decoupling your code]]></title>
            <link>https://medium.com/laravel-ramblings/simple-example-of-decoupling-your-code-c4c468bd6164?source=rss-36e8ac24d38c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4c468bd6164</guid>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Deric Cain]]></dc:creator>
            <pubDate>Sat, 24 Dec 2016 13:31:47 GMT</pubDate>
            <atom:updated>2016-12-27T23:35:10.673Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tightly coupled</h3><p>Currently, I am working on a rather large project and I have clearly seen the benefits of keeping your code decoupled. Now, I’m not going to go all extreme here and say that everything should be decoupled in the utmost fashion, but I will give you a very simple example of how decoupling can save you a major headache when things change in your codebase.</p><p><em>I work mainly with Laravel, so I will give an example using Laravel’s Eloquent models, but this example can be applied easily to a non-Laravel project.</em></p><p>Let’s say you have a User model and for that model, you have an attribute column in your database named is_admin to denote who the admins are within your application. At various places in your application, you need to check to see if the authenticated user is an admin so you know whether the user can do specific things. Here is what you would do:</p><pre>if (Auth::user()-&gt;is_admin) {</pre><pre>    // they can do whatever they want</pre><pre>}</pre><p>This works like a charm so you use it in a ton of places in your application. I mean, this works until your customer says, <em>“Well, we need two different kinds of admins.”</em></p><p>This example may still work, but it may not. You may have to rename the is_admin column in your database to something different, and since you have your code so tightly coupled with your database, you will need to search for all of the places that you checked for is_admin and update it with the new column name.</p><h3>A little looser</h3><p>Instead of taking the above approach, a very simple solution would be to create a method on your user model that checks to see if they are and admin. Let’s see what that looks like.</p><pre>class User extends Model</pre><pre>{</pre><pre>    public function isAdmin()</pre><pre>    {</pre><pre>        // If the column changes again, just change<br>        // it here and you’re good to go</pre><pre>        return $this-&gt;is_admin;</pre><pre>    }</pre><pre>}</pre><p>Now, you can do your checks within your application like so:</p><pre>if (Auth::user()-&gt;isAdmin()) {</pre><pre>    // they can do whatever they want</pre><pre>}</pre><p>And if your database column name changes, it’s all good. All you have to do is change it once in your model because your isAdmin() method takes care of the check for you.</p><p>I know this is an elementary example, but its an easy example to understand and its a great starting point and way to start thinking about how your application code should be loosely coupled in order to make your life easier.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4c468bd6164" width="1" height="1" alt=""><hr><p><a href="https://medium.com/laravel-ramblings/simple-example-of-decoupling-your-code-c4c468bd6164">Simple example of decoupling your code</a> was originally published in <a href="https://medium.com/laravel-ramblings">Geek Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using the Repository Pattern in Laravel 5]]></title>
            <link>https://medium.com/laravel-ramblings/using-the-repository-pattern-in-laravel-5-f7c6388db8d0?source=rss-36e8ac24d38c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7c6388db8d0</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Deric Cain]]></dc:creator>
            <pubDate>Mon, 21 Nov 2016 23:25:20 GMT</pubDate>
            <atom:updated>2016-11-22T11:24:09.440Z</atom:updated>
            <content:encoded><![CDATA[<p>The Repository Pattern is a very useful pattern with a couple of great uses. The first use is the abstraction that it provides. Meaning, it adds another layer between your application logic and your database. When tackling separation of concerns, this is very important. Another benefit is how easy it makes it to swap out your backend technology. For instance, let’s say you are using MySQL and want to change to MongoDB. Since the Repository Pattern uses interfaces as contracts, your application logic will remain the same and all you have to do is change out the repository. Sounds easy, right? Let’s dive in with a simple example.</p><h3>Creating the Repository Interface</h3><p>If you don’t know what interfaces are, have a look <a href="http://www.paulund.co.uk/using-interface-and-abstract-classes-in-php">here</a> before you go any further. We need an interface to act like a contract for our repositories. What do I mean by contract? Just like a written contract which descibes the confines of a specific obligation, an interface is the same for our code. It says that any class implementing the interface <em>must</em> perform specific actions. Or, in our case, must contain specific methods.</p><p>I will use the ever-popular blog scenario and create a post repository, as well as a comment respository. So, create a folder inside of the app folder and name it Repositories. Then, create a file and name it PostRepositoryInterface.php. This will be our interface. Within that interface, you will want to add this code:</p><pre>&lt;?php</pre><pre>namespace App\Repositories;</pre><pre>interface PostRepositoryInterface</pre><pre>{</pre><pre>}</pre><p>Now, we will need to the contracts, or methods, that we want our PostRepository to implement. It will looks something like this:</p><pre>&lt;?php</pre><pre>namespace App\Repositories;</pre><pre>interface PostRepositoryInterface<br>{<br>   /**<br>     * Get&#39;s a post by it&#39;s ID<br>     *<br>     * <a href="http://twitter.com/param">@param</a> int<br>     */<br>   public function get($post_id);<br>  <br>   /**<br>     * Get&#39;s all posts.<br>     *<br>     * <a href="http://twitter.com/return">@return</a> mixed<br>     */<br>   public function all();<br>  <br>   /**<br>     * Deletes a post.<br>     *<br>     * <a href="http://twitter.com/param">@param</a> int<br>     */<br>   public function delete($post_id);<br>  <br>   /**<br>     * Updates a post.<br>     *<br>     * <a href="http://twitter.com/param">@param</a> int<br>     * <a href="http://twitter.com/param">@param</a> array<br>     */<br>   public function update($post_id, array $post_data);<br>}</pre><p>Notice how there are not opening and closing curly braces. That is because no logic is stored in the interface — only the methods that we want our class to implement.</p><h3>Creating the Repository</h3><p>Now, we need to create our class. Within the same folder, `Repositories`, create a file and name it `PostRepository.php`. For this class, we will use the `implements` keyword to specify that we want to implement our interface. It should look like this:</p><pre>&lt;?php</pre><pre>namespace App\Repositories;</pre><pre>class PostRepository implements PostRepositoryInterface</pre><pre>{</pre><pre>}</pre><p>We must create the methods that declared in our interface. If we don’t, we will get an error at runtime and we will not be able to use our class. We will want to go ahead and add the logic that we will use to work with out posts. For this, I will include our Eloquent model `Post`.</p><pre>&lt;?php</pre><pre>namespace App\Repositories;</pre><pre>use App\Post;</pre><pre>class PostRepository implements PostRepositoryInterface</pre><pre>{</pre><pre>/**</pre><pre>* Get’s a post by it’s ID</pre><pre>*</pre><pre>* @param int</pre><pre>* @return collection</pre><pre>*/</pre><pre>public function get($post_id)</pre><pre>{</pre><pre>    return Post::find($post_id);</pre><pre>}</pre><pre>/**</pre><pre>* Get’s all posts.</pre><pre>*</pre><pre>* @return mixed</pre><pre>*/</pre><pre>public function all()</pre><pre>{</pre><pre>    return Post::all();</pre><pre>}</pre><pre>/**</pre><pre>* Deletes a post.</pre><pre>*</pre><pre>* @param int</pre><pre>*/</pre><pre>public function delete($post_id)</pre><pre>{</pre><pre>    Post::destroy($post_id)</pre><pre>}</pre><pre>/**</pre><pre>* Updates a post.</pre><pre>*</pre><pre>* @param int</pre><pre>* @param array</pre><pre>*/</pre><pre>public function update($post_id, array $post_data)</pre><pre>{</pre><pre>    Post::find($post_id)-&gt;update($post_data);</pre><pre>}</pre><pre>}</pre><p>Our class is now happy because it is using all of the methods defined by our interface. Now that we have our class and our interface created, be need to register our repository with Laravel’s container.</p><h3>Registering our Repository with Laravel’s IoC Container</h3><p>Create a file called BackendServiceProvider.php within the same folder — Repositories. This file will serve as a connector to Laravel’s IoC Container and allow us to use depency injection to inject our repository interfaces. More on that in a second…</p><p>Here is the BackendServiceProvider.php:</p><pre>&lt;?php</pre><pre>namespace App\Repositories;</pre><pre>use Illuminate\Support\ServiceProvider;</pre><pre>class BackendServiceProvider extends ServiceProvider</pre><pre>{</pre><pre>public function register()</pre><pre>{</pre><pre>    $this-&gt;app-&gt;bind(</pre><pre>        ‘App\Repositories\PostRepositoryInterface’,</pre><pre>        ‘App\Repositories\PostRepository’</pre><pre>    );</pre><pre>}</pre><pre>}</pre><p>The one thing to notice here is the order in which the interface and the class are bound. If you try and bind ’App\Repositories\PostRepository’ before ’App\Repositories\PostRepositoryInterface’, you will get an error. You must bind the interface first.</p><h3>Still with me?</h3><p>Just to make sure you’re following along, you should have a folder structure like this:</p><pre>- app</pre><pre> — — Repositories</pre><pre> — — — BackendServiceProvider.php</pre><pre> — — — PostRepositoryInterface.php</pre><pre> — — — PostRepository.php</pre><p>Of course, there will be other folders and files within the `app` directory, but you get the point.</p><h3>Using the Repository in a Controller</h3><p>It’s time to use our shiny, new repository. The place to use this is our controller. I will assume that you have a `PostController.php` class and that is your controller that handles everything to do with your posts. If you use some other controller, that is fine too. What we want to do is inject our interface into the controller when the controller gets instantiated. That way we can use the repository for all of our interactions with our posts model. Check it out:</p><pre>&lt;?php</pre><pre>namespace App\Http\Controllers;</pre><pre>use App\Http\Requests;</pre><pre>use App\Repositories\PostRepositoryInterface;</pre><pre>class PostController extends Controller</pre><pre>{</pre><pre><br>protected $post;</pre><pre><br>/**</pre><pre>* PostController constructor.</pre><pre>*</pre><pre>* @param PostRepositoryInterface $post</pre><pre>*/</pre><pre>public function __construct(PostRepositoryInterface $post)</pre><pre>{</pre><pre>    $this-&gt;post = $post;</pre><pre>}</pre><pre>/**</pre><pre>* List all posts.</pre><pre>*</pre><pre>* @return mixed</pre><pre>*/</pre><pre>public function index()</pre><pre>{</pre><pre>    $data = [</pre><pre>        ‘posts’ =&gt; $this-&gt;post-&gt;all()</pre><pre>    ];</pre><pre>    return view(‘templates.posts’, $data)</pre><pre>}</pre><pre>}</pre><p>The first thing that we do is inject our PostRepositoryInterface into our constructor. Then, we set our $post instance variable to an instance of our PostRepository object through our interface. This allows us to call the methods in our PostRepository class like we did in the index() method. Now we can do this:</p><pre>$this-&gt;post-&gt;update($data_array);</pre><pre>$this-&gt;post-&gt;delete($post_id);</pre><pre>$this-&gt;post-&gt;get($post_id);</pre><p>This keeps us from directly accessing our model like Post::find($id); which adds another layer of abstraction to our application. Don’t forget, should we stop using MySQL and start using MongoDB, or some other backend technology, all we have to do is swap out our PostRepository logic. This works because we are accessing the repository through our interface. This means that the code in our controller would not change at all. That’s a big win!</p><h3>More than one Repository? Sure.</h3><p>So, you need to create another repository because just having one repository is lame. Right? All you need to do is create an interface and then create a repository. Then, register them with Laravel’s IoC Container in our backend service provider file. I’ll use a Comment model to show you how.</p><p>Our directory would now look like this:</p><pre>app</pre><pre>- Repositories</pre><pre> — — BackendServiceProvider.php</pre><pre> — — — PostRepositoryInterface.php</pre><pre> — — — PostRepository.php</pre><pre> — — — CommentRepositoryInterface.php</pre><pre> — — — CommentRepository.php</pre><p>You would create the comment repository interface the same exact way as we did the post repository interface:</p><p>CommentRepositoryInterface.php</p><pre>&lt;?php</pre><pre><br>namespace App\Repositories;</pre><pre><br>interface CommentRepositoryInterface</pre><pre>{</pre><pre>    // Define all methods here but remember not to use curly braces.</pre><pre>    public function all(); // Like this..</pre><pre>}</pre><p>And our CommentRepository.php</p><pre>&lt;?php</pre><pre>namespace App\Repositories;</pre><pre><br>use App\Comment;</pre><pre><br>class CommentRepository implements CommentRepositoryInterface</pre><pre>{</pre><pre>    // Must use all methods that were defined in the CommentRepositoryInterface here</pre><pre>public function all()</pre><pre>{</pre><pre>    return Comment::all();</pre><pre>}</pre><pre>}</pre><p>The last thing that you will need to do is register it with the IoC Container in our BackendServiceProvider.php. That file will now look like this…</p><pre>&lt;?php</pre><pre>namespace App\Repositories;</pre><pre><br>use Illuminate\Support\ServiceProvider;</pre><pre><br>class BackendServiceProvider extends ServiceProvider</pre><pre>{</pre><pre>public function register()</pre><pre>{</pre><pre>    $this-&gt;app-&gt;bind(</pre><pre>        ‘App\Repositories\PostRepositoryInterface’,</pre><pre>        ‘App\Repositories\PostRepository’</pre><pre>    );</pre><pre>    $this-&gt;app-&gt;bind(</pre><pre>        ‘App\Repositories\CommentRepositoryInterface’,</pre><pre>        ‘App\Repositories\CommentRepository’</pre><pre>    );</pre><pre>}</pre><pre>}</pre><p>Again, pay attention to the order in which you list your interface and class.</p><h3>Finished. Doesn’t that feel good?</h3><p>You should have a fully functional repository design pattern implemented with Laravel 5. If you have any questions or comments, <a href="https://twitter.com/dericcain">follow me</a> up on Twitter!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7c6388db8d0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/laravel-ramblings/using-the-repository-pattern-in-laravel-5-f7c6388db8d0">Using the Repository Pattern in Laravel 5</a> was originally published in <a href="https://medium.com/laravel-ramblings">Geek Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arrays are everywhere!]]></title>
            <link>https://medium.com/laravel-ramblings/arrays-are-everywhere-part-1-2b3773c6eab9?source=rss-36e8ac24d38c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b3773c6eab9</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Deric Cain]]></dc:creator>
            <pubDate>Sun, 20 Nov 2016 15:06:34 GMT</pubDate>
            <atom:updated>2016-12-27T23:33:54.174Z</atom:updated>
            <content:encoded><![CDATA[<p>March 18th, 2016</p><p>One of the most used data types in development is arrays. They are used so much, in fact, that PHP has a ton of different built-in array functions. I am going to do a series of the different array functions that PHP offers. Let’s look at a couple and how they can be useful.</p><h3>array_unique()</h3><p>If you have an array that may contain duplicate values, array_unique() could come in handy to help you get only the values that are unique. Think of it like MySQL’s DISTINCT clause For example…</p><pre>$colors = [<br>  &#39;red&#39;,<br>  &#39;green&#39;,<br>  &#39;yellow&#39;,<br>  &#39;green&#39;,<br>  &#39;blue&#39;,<br>  &#39;red&#39;<br>];<br><br>$unique_colors = array_unique($colors);<br><br>// Output...<br>$unique_colors = [<br>  &#39;red&#39;,<br>  &#39;green&#39;,<br>  &#39;yellow&#39;,<br>  &#39;blue&#39;<br>];</pre><p>It’s an easy way to get an array without the duplicate values.</p><h3>array_map()</h3><p>If you need to apply a function to all of the values in an array, array_map() is a great function for that. Let’s say we have a form with quite a few fields which we want to collect and pass to a DB. Of course, this form will need to be sanitized. array_map() can help us with that. We will create a method called sanitize()</p><p><em>Disclaimer: I am in no way saying this is all you need to do to secure user inputted data. This is just an example of a helper</em></p><pre>/**<br> * Sanitizes the $_POST array.<br> *<br> * @param $post_data<br> * @return array<br> */<br>public static function sanitize($post_data)<br>{<br>  // Take the parameter and use a callback function to clean the data.<br>  // $post_field represents each input field in the form<br>  $post_array = array_map(function ($post_field) {<br>    // Run strip_tags and trim the data from the field<br>    return strip_tags(trim($post_field));<br>  }, $post_data);<br><br>  // Send the sanitized array back<br>  return $post_array;<br>}</pre><p>Now, we have a static method that can be called when we need to sanitize some user inputted data. We can call it like Validate::sanitize($_POST) assuming that the sanitize() method lives in the Validate class. Of course, you are not limited to just applying sanitize methods to each class, you can apply any function needed to each value in the array.</p><p>I will look at some more array functions in another post. If you have any suggestions or comments, <a href="https://twitter.com/dericcain">follow me</a> on Twitter and give me shout!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b3773c6eab9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/laravel-ramblings/arrays-are-everywhere-part-1-2b3773c6eab9">Arrays are everywhere!</a> was originally published in <a href="https://medium.com/laravel-ramblings">Geek Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I Decided To Embrace Laravel]]></title>
            <link>https://medium.com/laravel-ramblings/why-i-decided-to-embrace-laravel-4621b129f3fd?source=rss-36e8ac24d38c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4621b129f3fd</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Deric Cain]]></dc:creator>
            <pubDate>Sun, 20 Nov 2016 15:04:27 GMT</pubDate>
            <atom:updated>2016-11-20T15:04:27.809Z</atom:updated>
            <content:encoded><![CDATA[<p>Why I Decided To Embrace Laravel</p><p>May 2nd, 2016</p><p>Over the last year, I took part in three large projects. My task was to move away from the old architecture based on PHP and server-side HTML generation, and transition to REST API.</p><p>With the old approach, back-end developers were expected to know much more about the UI and visual aspects of the application. Because of this, they had to pay attention to different segments of the application, instead of focusing on their primary objective. Having the back-end API strictly separated from the UI allowed our developers to focus on the quality of their code.</p><p>Also, testing API services is much easier as REST API can be verified by automated unit testing.</p><p>I’ve had some experience in writing my own framework, as well as working with Yii, CakePHP, CodeIgniter, Slim Framework, Symfony and few other open source frameworks. Each time, I’ve experienced a lack of functionality or awkward approach to some problems.</p><p>I used Laravel for four months before deciding to choose it as the platform for our next project. The project itself was a great success and this article is a product of this experience. Now I am able to call myself a Laravel developer.</p><h3>Why I Chose Laravel</h3><p>I’ve already outlined some of my reasons for using Laravel and my experience, so let’s take a closer look at what made Laravel a better choice for my latest project:</p><ul><li>Quick and functional core that can be extended</li><li>Clean and simple routing</li><li>Effective ORM and database layer</li><li>Easy integration with third-party libraries (AWS, export libs, etc.). You can use Composer or Packagist to include libraries in your project</li><li>Active and growing community that can provide quick support and answers</li><li>Supporting unit tests out of the box</li><li>Async queue and background jobs for the long running tasks</li></ul><h3>Laravel Core And Routing</h3><p>The Laravel kernel is hosted on GitHub. The kernel implements an IoC pattern allowing customization and rewriting of any part of the framework (request, logging, authentication, etc.).</p><p>Laravel designers didn’t spend too much time reinventing the wheel. A lot of solutions and practices are transferred from other frameworks. A good example of this approach is the extended Symfony console called Artisan, which is a command-line interface included with Laravel.</p><h3>Routing</h3><p>Routing in Laravel is amazing; it is very similar to the Ruby on Rails (RoR) implementation, which I like a lot. You can easily group routes, create resources for CRUD pages, attach filters and automatically bind models to the request parameters.</p><p>Nested routes are a very useful feature:</p><pre>Route::group([&#39;prefix&#39;=&gt;&#39;level0&#39;], function() { <br>    Route::get(&#39;/&#39;, array(&#39;uses&#39; =&gt; &#39;TestController@level0&#39;));<br>    Route::group([&#39;prefix&#39;=&gt;&#39;/{level0}/level1&#39;], function(){<br>        Route::get(&#39;/&#39;, array(&#39;uses&#39; =&gt; &#39;TestController@level1&#39;));<br>        Route::post(&#39;/{custom_variable}/custom_route&#39;, <br>            array(&#39;uses&#39; =&gt; &#39;CustomConroller@custom_route&#39;)); <br>        }); <br>    });</pre><pre>});</pre><p>Versioning can be implemented as a group on the top level for all nested routes by using the ‘v1’ prefix. When we change the API version, we can retain the old one and use the ‘v2’ prefix to start implementation of routes with new code and logic, i.e., new references to controllers and actions.</p><p>Let’s take a step-by-step look at everything used in this Laravel tutorial:</p><p>A defined group of routes with path level0 at top level of our API.</p><p>If we have a call BASEURL/level0, then Laravel will resolve it and call method level0() of TestController to process the request.</p><p>We have a sub-group with the {level0}/level1 pattern. To access API resources inside this group we should use the path for the parent group (level0) and match the pattern of our sub-group ({level0}/level1). For example, level0/777/level1 is the correct path for this sub-group of our API. Here we have 777 as the variable level0 that Laravel will path to the handler of the routes inside the sub-group.</p><p>In the the end we have two sample routes:</p><p>BASEURL/level0/777/level1 - GET request to this URI will be processed with method level1($level0) of TestController where the first parameter is {level0} and it will be initialized with value 777.</p><p>BASEURL/level0/777/level1/888/custom_variable - POST request to this URI will be processed using the custom_route($level0, $custom_variable) method of CustomController.</p><p>The parameters used in the method come from the route variables.</p><p>Finally, we can associate our variable {level0} in the route with a model, i.e., LevelModel. In this case, the framework automatically tries to find existing database records and pass it on as a parameter to the controller’s method.</p><p>It helps us write less code and we don’t need to write LevelModel::find($id) or LevelModel::findOrFail($id) in controllers.</p><p>The <a href="https://github.com/dingo/api">Dingo API package</a> takes routing one step further.</p><p>Here are a few features that Dingo provides to the framework:</p><ul><li>Transformers: Special objects for response customization (e.g., type-cast integers and boolean values, paginate results, include relationships, etc.)</li><li>Protect routes and allow different/custom authentication providers. Controller Trait provides protection of custom actions, while we can easily retrieve authenticated user info with API::user().</li><li>Limiting request count per user by using built-in or custom throttles. A powerful internal requests mechanism that allows requests on your API internally</li></ul><h3>Laravel uses Eloquent ORM</h3><p>Laravel is based on Eloquent ORM. I’ve used it with PostgreSQL and MySQL, and in both cases it performed flawlessly.</p><p>The official documentation is comprehensive, so there is no reason to repeat things in this article:</p><p>Query Scope — query logic is created as a function with a special scope prefix.</p><p>The following example shows the standard SQL Query transformed to a query function in Eloquent ORM:</p><pre>SELECT * WHERE hub_id = 100 AND (name LIKE `˜%searchkey%` OR surname LIKE `˜%searchkey%`):</pre><pre>function scopeByFieldListLike($query, $fields, $value){ <br>    $query-&gt;where(function($query) use ($fields, $value){<br>        foreach($fields as $field){ <br>            $query-&gt;orWhere($field , &#39;like&#39;, &quot;%&quot;.$value.&quot;%&quot;); <br>        } <br>     }); <br>     return $query; <br>}</pre><p>Using a function in your code is straightforward.</p><pre>$model = new User; $model-&gt;byFieldListLike([&#39;name&#39;, &#39;surname&#39;], &#39;searchkey&#39;);</pre><p>A lot Eloquent methods return an instance of the QueryBuilder. You can use almost all of these methods on models.</p><p>Like what you’re reading?Get the latest updates first.</p><p>Enter your email address… Get Exclusive Updates No spam. Just great engineering and design posts.</p><h3>Unit Testing</h3><p>Writing unit tests is usually very time consuming, however, it’s definitely worth the time, so please do it.</p><p>Laravel relies on a TestCase base class for this task. It creates a new instance of the application, resolves the route and runs the controller method in its own sandbox. However, it does not run application filters (App::before and App::after) or more complex routing scenarios. To enable these filters in a sandbox environment, I had to manually enable them by using Route::enableFilters().</p><p>Obviously, if you know how to use Laravel, you know it could use some more work in the unit testing segment. I’ve set up a few functions that helped me create more advanced unit tests. Feel free to take these and use them in your projects.</p><p>To perform more advanced real-life testing and implement “curl-like” requests, I used the kriswallsmith/buzz library. This provided me with a much needed feature set for testing, including custom headers and uploading files.</p><p>The code below shows the function you can use to execute this kind of test:</p><pre>public function browserRequest($method, $resource, $data = [], $headers = [], $files = [])<br>{<br>    $host = $this-&gt;baseUrl();<br>    if (count($files)){<br>        // Use another form request for handling files uploading<br>        $this-&gt;_request = new Buzz\Message\Form\FormRequest($method, $resource, $host);<br>        if (isset($headers[&#39;Content-Type&#39;])) {<br>            // we don&#39;t need application/json, it should form/multipart-data<br>            unset($headers[&#39;Content-Type&#39;]);<br>        }<br>        $this-&gt;_request-&gt;setHeaders($headers);<br>        $this-&gt;_request-&gt;setFields($data);<br>        foreach($files as $file) {<br>            $upload = new Buzz\Message\Form\FormUpload($file[&#39;path&#39;]);<br>            $upload-&gt;setName($file[&#39;name&#39;]);<br>            $this-&gt;_request-&gt;setField($file[&#39;name&#39;], $upload);<br>        }<br>        $response = new Buzz\Message\Response();<br>        $client = new Buzz\Client\FileGetContents();<br>        $client-&gt;setTimeout(60);//Set longer timout, default is 5<br>        $client-&gt;send($this-&gt;_request, $response);<br>    } else {<br>        $this-&gt;_request = new Buzz\Message\Request($method, $resource, $host);<br>        $this-&gt;_request-&gt;setContent(json_encode($data));<br>        $this-&gt;_request-&gt;setHeaders($headers);<br>        $response = new Buzz\Message\Response();<br>        $client = new Buzz\Client\FileGetContents();<br>        $client-&gt;setTimeout(60);//Set longer timout, default is 5<br>        $client-&gt;send($this-&gt;_request, $response);<br>    }<br>    return $response;<br>}</pre><p>I am a very lazy developer, so I added optional parameters that allowed me to decode responses, extract data, and check the response codes. This led to another method that includes default headers, authorization tokens and some additional functionality.</p><pre>public function request($method, $path, $data = [], $autoCheckStatus = true, $autoDecode = true, $files = [])<br>{<br>    if (!is_array($data)){<br>        $data = array();<br>    }<br>    $servers = [&#39;Content-Type&#39; =&gt; &#39;application/json&#39;];<br>    if ($this-&gt;_token){<br>        $servers[&#39;authorization&#39;] = &#39;Token &#39; . $this-&gt;_token;<br>    }<br>    $this-&gt;_response = $this-&gt;browserRequest($method, $path, $data, $servers, $files);<br>    if ($autoCheckStatus === true){<br>        $this-&gt;assertTrue($this-&gt;_response-&gt;isOk());<br>    } elseif(ctype_alnum($autoCheckStatus)){<br>        $this-&gt;assertEquals($autoCheckStatus, $this-&gt;_response-&gt;getStatusCode());<br>    }<br>    if ($autoDecode){<br>        $dataObject = json_decode($this-&gt;_response-&gt;getContent());<br>        if (is_object($dataObject))<br>        {<br>            // we have object at response<br>            return $this-&gt;_dataKeyAtResponse &amp;&amp; property_exists($dataObject, $this-&gt;_dataKeyAtResponse) ? $dataObject-&gt;{$this-&gt;_dataKeyAtResponse} : $dataObject;<br>        }<br>        elseif (is_array($dataObject))<br>        {<br>            // perhaps we have a collection<br>            return $this-&gt;_dataKeyAtResponse &amp;&amp; array_key_exists($this-&gt;_dataKeyAtResponse, $dataObject) ? $dataObject[$this-&gt;_dataKeyAtResponse] : $dataObject;<br>        }<br>        else<br>        {<br>            // Uknown result<br>            return $dataObject;<br>        }<br>    } else {<br>        return $this-&gt;_response-&gt;getContent();<br>    }<br>}</pre><p>Once again, my lazy habits made me add wrappers designed to test CRUD pages:</p><pre>create($data = [], $autoCheckStatus = true, $autoDecode = true, $files = []) show($id, $data = [], $autoCheckStatus = true, $autoDecode = true) update($id, $data = [], $autoCheckStatus = true, $autoDecode = true, $files = []) delete($id, $data = [], $autoCheckStatus = 204, $autoDecode = false) index($data = [], $autoCheckStatus = true, $autoDecode = true)</pre><p>A simple test code would look like this:</p><pre>// send wrong request<br>// Validation error has code 422 in out specs<br>$response = $this-&gt;create([&#39;title&#39;=&gt;&#39;&#39;, &#39;intro&#39;=&gt;&#39;Ha-ha-ha. We have validators&#39;], 422);<br>// Try to create correct webshop<br>$dataObject = $this-&gt;create(<br>    $data = [<br>        &#39;title&#39;=&gt;&#39;Super webshop&#39;,<br>        &#39;intro&#39;=&gt;&#39;I am webshop&#39;,<br>    ]<br>);<br>$this-&gt;assertGreaterThan(0, $dataObject-&gt;id);<br>$this-&gt;assertData($data, $dataObject);<br><br>// Try to request existing resource with method GET<br>$checkData = $this-&gt;show($dataObject-&gt;id);<br>// assertData is also a help method for validation objects with nested structure (not a part of PHPUnit).<br>$this-&gt;assertData($data, $checkData);<br><br>// Try to update with not valid data<br>$this-&gt;update($dataObject-&gt;id, [&#39;title&#39;=&gt; $data[&#39;title&#39;] = &#39;&#39;], 422);<br><br>// Try to update only title. Description should have old value. Title - changed<br>$this-&gt;update($dataObject-&gt;id, [&#39;title&#39;=&gt; $data[&#39;title&#39;] = &#39;Super-Super SHOP!!!&#39;]);<br><br>// Then check result with reading resource<br>$checkData = $this-&gt;show($dataObject-&gt;id);<br>$this-&gt;assertData($data, $checkData);<br><br>// Read all created resources<br>$list = $this-&gt;index();<br>$this-&gt;assertCount(1, $list);<br>// TODO:: add checking for each item in the collection<br><br>// Delete resoure<br>$this-&gt;delete($dataObject-&gt;id);<br>$this-&gt;show($dataObject-&gt;id, [], 404);</pre><p>Here is another useful function for validating response data including relations and nested data:</p><pre>public function assertData($input, $checkData){<br>// it could be stdClass object after decoding json response<br>    $checkData = (array)$checkData;<br>    foreach($input as $k=&gt;$v){<br>        if (is_array($v) &amp;&amp; (is_object($checkData[$k]) || is_array($checkData[$k]))) {<br>            // checking nested data recursively only if it exists in both: response data($input) and expected($checkData)<br>           $this-&gt;assertData($v, $checkData[$k]);<br>        } else {<br>           $this-&gt;assertEquals($v, $checkData[$k]);<br>        }<br>    }<br>}</pre><h3>Queuing</h3><p>Long running tasks are a common bottleneck in web applications. A simple example would be the creation of a PDF report and its distribution inside an organisation, which can take a lot of time.</p><p>Blocking user requests to perform this action is not a desirable way of addressing the issue. Using Queue in Laravel is a great way of handling and queuing long running tasks in the background.</p><p>One of the last issues was PDF generation and sending reports via email. I used a default queue driver for Beanstalkd, supported with the package pda/pheanstalk. It is very easy to add tasks to the queue</p><p>For example, generating and sending PDFs could be done like this:</p><pre>\Queue::push(&#39;\FlexiCall\Queue\PdfSend&#39;, [....data for sending to job&#39;s handler..], &#39;default&#39;);</pre><p>Our PdfSend handler could be implemented like this:</p><pre>class PdfSend extends BaseQueue{<br>    function fire($job, $data){<br>        //.............................<br>        //..... OUR IMPLEMENTATION.....<br>        //.............................<br>    }<br>}</pre><p>Laravel specifications suggest tracking a queue with — daemon options, but I use the supervisor daemon that keeps it running permanently:</p><p>php artisan queue:listen --env=YOUR_ENV</p><p>Queues are great for tasks like saving data. They can be used to repeat failed jobs, add sleep timeouts before executing jobs, etc.</p><h3>Putting It All Together</h3><p>I’ve mentioned few key points related to Laravel development in this Laravel review. How you put it all together and build your application will depend on your specific setup and project. However, here is a brief checklist of steps you might want to consider:</p><ul><li>Setup homestead Vagrant box prepared for development using Laravel and configured local environment.</li><li>Add endpoints (configure routes).</li><li>Add authentication layer.</li><li>Add filters before/after application execution, giving you an option to run anything before and after application is executed. Additionally, you can define filters for any route.</li></ul><p>My default “before” filter creates a global scope as a singleton and starts the timer for monitoring performance:</p><pre>class AppBefore { function filter($request) {<br>    \App::singleton(&#39;scope&#39;, function() { <br>        $scope = new AppScope();//My scope implementation<br>        $scope-&gt;startTimer(); <br>        <br>        return $scope; <br>     }); <br>} </pre><p>The “after” filter stops the timer, logs it to the performance log, and sends CORS headers.</p><pre>class AppBefore {<br>    function filter($request) {<br>        \App::singleton(&#39;scope&#39;, function() {<br>            $scope = new AppScope();//My scope implementation<br>            $scope-&gt;startTimer();</pre><pre>            return $scope;<br>        });<br>    }<br>}</pre><p>Developing each of your modules will likely require these steps:</p><p>Setup data migration, and seed default data. Implement models and relations, transformers, validators and sanitizers (if needed). Write unit tests. Implement controllers and execute tests.</p><h3>Wrap Up</h3><p>I’ve been using Laravel for over a year. As with any technology, there were some teething problems, but I believe that learning Laravel has convinved me that it is an amazing framework. There are a few more things that I haven’t mentioned in this Laravel tutorial, but if you are interested in learning more, you may want to consider these points and features:</p><ul><li>Powerful model for subscribing and listening to application events.</li><li>Support for Amazon SDK aws/aws-sdk-php.</li><li>Caching.</li><li>Own templating engine called Blade, if you like building the application “the old way” without RESTful backend and UI separation.</li><li>Simple configuration.</li><li>Built-in Stripe billing module.</li><li>Out of the box localization.</li><li>Catching and handling most errors.</li></ul><p>Good luck and stay tuned, Laravel is a promising framework and I believe it will be around for years to come</p><p>** This was a guest post from here: <a href="https://www.toptal.com/laravel/why-i-decided-to-embrace-laravel">https://www.toptal.com/laravel/why-i-decided-to-embrace-laravel</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4621b129f3fd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/laravel-ramblings/why-i-decided-to-embrace-laravel-4621b129f3fd">Why I Decided To Embrace Laravel</a> was originally published in <a href="https://medium.com/laravel-ramblings">Geek Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I switched from PhpStorm to Sublime… and the back to PhpStorm]]></title>
            <link>https://medium.com/laravel-ramblings/why-i-switched-from-phpstorm-to-sublime-and-the-back-to-phpstorm-415cbc5b652?source=rss-36e8ac24d38c------2</link>
            <guid isPermaLink="false">https://medium.com/p/415cbc5b652</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[phpstorm]]></category>
            <category><![CDATA[sublimetext]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Deric Cain]]></dc:creator>
            <pubDate>Sun, 20 Nov 2016 14:36:55 GMT</pubDate>
            <atom:updated>2016-11-21T11:43:02.666Z</atom:updated>
            <content:encoded><![CDATA[<h3>The beginning</h3><p>To be quite honest, <a href="https://www.sublimetext.com/">Sublime Text</a> was the first editor that I ever used. I was so new to coding that I didn’t really understand enough about editors to grasp a real difference. Somehow, I found out that I could get <a href="https://www.jetbrains.com/phpstorm/">PhpStorm</a> for free since I was a student, so I jumped at the opportunity to try something new. Plus, it looked like it was the Lamborghini of editors. So, I made the switch.</p><p>At this point, I just started learning <a href="https://laravel.com/">Laravel</a> and one of the things that I liked the most was the code completion that PhpStorm offered. It allowed me to scroll through methods. This really helped me in learning the Laravel framework. There was some issues with PhpStorm and Laravel Facades, but there is a <a href="https://github.com/barryvdh/laravel-ide-helper">package</a> that fixes this. For the next year, I would use PhpStorm exclusively and I loved it. Here are some other features that I loved:</p><p><strong>Customization</strong> — I am not sure there is a part of PhpStorm that is not customizable. This is a huge plus because I can cater it to how I want/need it to work.</p><p><strong>Refactoring</strong> — PhpStorm makes it really easy to refactor a block of code to a method, rename a variable throughout your codebase, pull a method up to a parent class, etc. This is a huge timesaver.</p><p><strong>Terminal</strong> — there is a built-in terminal that makes it quick and easy to run terminal commands.</p><p><strong>Live Templates</strong> — These are basically snippets of code that can be produced by type a command. For instance, if I want to start a public function, all I have to do is type pubf and this appears:</p><pre>public function ()</pre><pre>{</pre><pre>}</pre><p>The good thing about this is that the cursor start before the parenthesis so I can name the method. When I hit tab, the cursor moves to inside the parenthesis so I can create parameters and then when I hit tab again, the cursor moves to the body of the method so I can start creating my method. But that’s just one example and there are many-many more.</p><p><strong>Step Dubugging</strong> — Although this took me some time to figure out how to set it up, I have found that this is way better than using var_dump() or dd() everywhere, at least in a lot of cases.</p><p><strong>Testing</strong> — Running tests inside of PhpStorm works really well too. It just keeps everything inside of the terminal so I don’t have to open a separate window.</p><p>There are many more features that I have not mentioned here and that’s just because PhpStorm is a huge IDE and has a ton timesaving features.</p><h3>If PhpStorm is so good, why the switch?</h3><p>I started a new job and I they provide a Mac Mini in which I use to write code all day. Of course, I installed PhpStorm as my editor but I noticed that it ran really slow. I mean, it was so slow that I just couldn’t use it. I would hit ⌘ + p to search for a file and start typing the filename. It took so long for the window to pop up that PhpStorm would miss the first few letters of the filename that I typed…. That’s how slow…. This was not feasible for me to accomplish my tasks. The thought of switching to something else broke my heart (not really but you get it).</p><h3>In the red corner, Sublime Text! (*crowd cheers*)</h3><p>I broke out Sublime Text and started using it. I bought Wes Bos’s book <a href="https://sublimetextbook.com/">Sublime Text Power User</a> , which I cannot recommend enough if you use Sublime. I spent a couple of weeks getting everything how I wanted it in Sublime Text and man, was it lightening fast. No more lag… I was sure that my development time had sped up because of how lightweight and fast Sublime is. I actually wondered why I had been using PhpStorm and not Sublime at this point. Here are some things that I like about Sublime.</p><p><strong>Customization</strong> — It’s hard to beat the customization of PhpStorm, but Sublime may come close. And, most of the customization happens using JSON files, which makes it very simple.</p><p><strong>Plugins</strong> — There are a crap-load of plugins for Sublime. Basically, anything I needed to do, Sublime had a plugin for it and I could configure most plugins to cater them to my needs.</p><p><strong>Themes</strong> — There are a ton of themes out there to make the editor look how you want. You can even hack away at an installed theme and customize it even more.</p><p><strong>Speed</strong> — I don’t think there is an editor out there that is as fast as Sublime. I haven’t tried them all, but Sublime is lightening fast.</p><h3>If Sublime Text is so good, why change?</h3><p>As much as I loved using Sublime text and was singing it’s praises, there were a few things that nagged me to no end. For instance, when I wanted to use an array nested inside a closure in PHP, it would never align the closing tags, which meant that I always had to correct it. Here is what it would look like before I fixed it:</p><pre>Route::group(‘/users’, [</pre><pre>// cursor lands here</pre><pre>] function() {</pre><pre>    }) // I had to move this back 4 spaces every single time…</pre><p>I know, that seems a bit picky, but when I do this multiple times a day, it gets very annoying. And there are many other things like this that made me miss PhpStorm so much.</p><p>One more example is when I would go to use Emmet in my HTML like so:</p><pre>.container&gt;.row&gt;.col-sm-12&gt;p.text</pre><p>It would expand to this…</p><pre>.container&gt;.row&gt;.col-sm-12&gt;&lt;p class=”text”&gt;&lt;/p&gt;</pre><p>Which means I would have to ⌘ + z and then hit tab again and hope it worked. Not huge, but again, when I do this a lot during the day, it was really annoying.</p><h3>And back to PhpStorm we go!</h3><p>I convinced my boss to buy a SSD drive so I could install it into the Mac Mini that I used and he agreed. This made the machine a lot faster. I opened up PhpStorm to see if it was usable, and boy oh boy, was it ever. It seems the SSD did the trick and made it perform as expected. I have not looked back and I <em>probably</em> won’t. I. Love. PhpStorm. It saves me so much time with all of the features that it offers. Yes, Sublime is faster, but it doesn’t save me as much time as PhpStorm does.</p><h3>Conclusion</h3><p>I still use Sublime for quick and dirty things like editing a single file, etc., but I use PhpStorm on my projects and I am very happy with it. If you have a fast enough computer to handle PhpStorm, I cannot recommend it enough. I would not ditch Sublime Text, as you may find that it is a great editor and you may like it better. Just my opinion, nothing compares to PhpStorm and how great it is to use.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=415cbc5b652" width="1" height="1" alt=""><hr><p><a href="https://medium.com/laravel-ramblings/why-i-switched-from-phpstorm-to-sublime-and-the-back-to-phpstorm-415cbc5b652">Why I switched from PhpStorm to Sublime… and the back to PhpStorm</a> was originally published in <a href="https://medium.com/laravel-ramblings">Geek Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[About]]></title>
            <link>https://medium.com/laravel-ramblings/about-b801a84f6b97?source=rss-36e8ac24d38c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b801a84f6b97</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Deric Cain]]></dc:creator>
            <pubDate>Sun, 20 Nov 2016 14:26:14 GMT</pubDate>
            <atom:updated>2016-11-20T14:26:14.325Z</atom:updated>
            <content:encoded><![CDATA[<p>I am a passionate developer who loves coding in PHP and using the Laravel framework. I started out as a front-end dev and then learned PHP when I was working on a few Wordpress projects. I fell in love with the backend stuff and started to devote time to learn the craft. I am a lifelong learner and I devote time each and every day to learn something new.</p><p>Aside from being a web developer, I am a husband and father and value my family above all. My personal core values are integrity and hard work. And, if it was possible to make coffee a core value, that would be one too :)</p><p>I would love to know if you have any tips for me or anything that you think that I would find interesting. <a href="https://twitter.com/dericcain">Follow me</a> on Twitter and let me know if you have any suggestions!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b801a84f6b97" width="1" height="1" alt=""><hr><p><a href="https://medium.com/laravel-ramblings/about-b801a84f6b97">About</a> was originally published in <a href="https://medium.com/laravel-ramblings">Geek Stuff</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>