<?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 Pete Hegman on Medium]]></title>
        <description><![CDATA[Stories by Pete Hegman on Medium]]></description>
        <link>https://medium.com/@petehegman?source=rss-d89afb154d30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_XWa47yKXOjT1IVH.</url>
            <title>Stories by Pete Hegman on Medium</title>
            <link>https://medium.com/@petehegman?source=rss-d89afb154d30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 09:45:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@petehegman/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 Deployment Pipelines With buddy.works]]></title>
            <link>https://medium.com/@petehegman/laravel-deployment-pipelines-with-buddy-works-341c95e7fce1?source=rss-d89afb154d30------2</link>
            <guid isPermaLink="false">https://medium.com/p/341c95e7fce1</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[digitalocean]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[phpunit]]></category>
            <dc:creator><![CDATA[Pete Hegman]]></dc:creator>
            <pubDate>Mon, 12 Feb 2018 04:27:07 GMT</pubDate>
            <atom:updated>2018-02-22T02:28:43.106Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently used <a href="https://buddy.works/">buddy.works</a> to setup a deployment pipeline and was very impressed with the service! I ran into a few snags along the way so figured I would share how I setup the pipeline. Buddy has a ton of actions that can be run in your pipeline but I am going to go over running unit and integration/feature tests with PHPUnit, inspecting code quality with PHP CodeSniffer and then deploying to DigitalOcean. I would encourage you to check out some of the other actions that Buddy offers.</p><h3>Creating a project</h3><p>The first step is to signup for <a href="https://buddy.works/">buddy.works</a> and create a new project. When you create a new project you can choose to hook into a number of repository services including GitHub, Bitbucket and GitLab. Choose your repository and create a new pipeline. Enter your pipeline name, how you would like to trigger the pipeline (I prefer “On Push”) and then choose what branch you would like to deploy from (usually master if you are deploying to production).</p><h3>PHPUnit</h3><p>After creating your pipeline its time to add some actions. Scroll down to the “EXECUTE BUILDS &amp; COMMANDS IN A DOCKER CONTAINER” section and choose “PHP”.</p><p>Next choose the version of PHP that matches your production environment, in my case it was 7.1.13.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6bwM9-vESMTbOzntUcABw.png" /><figcaption>Choose your PHP version</figcaption></figure><p>Because I was using a MySQL database for testing I had to setup MySQL. To do this click on the “Services” tab of the configuration and add a MySQL service from the dropdown. You can leave all the defaults as is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q-682Iz36DS9OSn04w4nIw.png" /><figcaption>Add the MySQL service for database testing</figcaption></figure><p>Next we need to setup the “Packages &amp; Setup Commands”. There are a number of packages we need to install in order to make sure Laravel can run properly. In the “Packages &amp; Setup Commands” tab. Add the following to the setup commands:</p><pre>apt-get update -yqq<br>apt-get install git mysql-client libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq<br># Compile PHP, include these extensions.<br>docker-php-ext-install mbstring mcrypt pdo_mysql curl json intl gd xml zip bz2 opcache<br>curl -sS <a href="https://getcomposer.org/installer">https://getcomposer.org/installer</a> | php -- --install-dir=/usr/local/bin --filename=composer</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_hwn_RqsUjzVTDmL0G_WPA.png" /><figcaption>Update the setup commands</figcaption></figure><p>This will install all the packages we need when the docker instance is spun up. It will also install composer so we can install all the Laravel dependencies.</p><p>Finally we need to configure the “Run Commands”. This is what is run after the docker instance is spun up. In the “Run Commands” section add the following:</p><pre>echo &quot;CREATE DATABASE IF NOT EXISTS name_of_your_testing_database&quot; | mysql --host=mysql --user=root --password=qwerty<br>composer install<br>php artisan key:generate<br>php artisan cache:clear<br>vendor/bin/phpunit</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZ8Unv8dPqMBAncxtuOOwA.png" /><figcaption>Update the Run Commands</figcaption></figure><p>What this does is:</p><ol><li>Creates the MySQL testing database (change to the name of your testing database).</li><li>Installs all composer project dependencies.</li><li>Generates the application key.</li><li>Clears the application cache.</li><li>Runs PHPUnit.</li></ol><p>Finally, since the .env file is gitignored we need to add it to our project. To do this head to your pipeline and click “Filesystem”. Then under “Options” click “New File”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2ZI2UDW1rcQW5N_LW_zMig.png" /><figcaption>Creating a .env file for testing</figcaption></figure><p>Create a .env file that is similar to this:</p><pre>APP_NAME=Laravel<br>APP_ENV=testing<br>APP_KEY=<br>APP_DEBUG=true<br>APP_LOG_LEVEL=debug<br>APP_URL=<a href="http://localhost/">http://localhost</a></pre><pre>DB_CONNECTION=mysql<br>DB_HOST=mysql<br>DB_PORT=3306<br>DB_DATABASE=name_of_your_testing_database<br>DB_USERNAME=root<br>DB_PASSWORD=qwerty</pre><pre>BROADCAST_DRIVER=pusher<br>CACHE_DRIVER=array<br>SESSION_DRIVER=array<br>SESSION_LIFETIME=120<br>QUEUE_DRIVER=sync</pre><pre>REDIS_HOST=127.0.0.1<br>REDIS_PASSWORD=null<br>REDIS_PORT=6379</pre><pre>MAIL_DRIVER=smtp<br>MAIL_HOST=smtp.mailtrap.io<br>MAIL_PORT=2525<br>MAIL_USERNAME=null<br>MAIL_PASSWORD=null<br>MAIL_ENCRYPTION=null</pre><pre>PUSHER_APP_ID=<br>PUSHER_APP_KEY=<br>PUSHER_APP_SECRET=</pre><h3>phpcs (PHP CodeSniffer)</h3><p>Now that we have PHPUnit setup lets setup an action to look for code violations.</p><p>Head back to your pipeline and click the plus sign after the PHPUnit action. Scroll to the “CODE QUALITY &amp; REVIEW” section and select PHP CodeSniffer. At the bottom select your PHP version. In the “Run Commands” section you have a couple of options. I personally like to check for violations and then manually correct them. To do this add phpcs app --standard=PSR2 to the “Run Commands” section so it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HuPF47hqVRJX7YsvDSqxKg.png" /><figcaption>PHP CodeSniffer checking for code violations</figcaption></figure><p>If you would like PHP CodeSniffer to correct any code violations you can change it to this command: phpcbf app --standard=PSR2 .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z701ZBs0CxVrYAda2v8I9A.png" /><figcaption>PHP CodeSniffer check for and correct any code violations</figcaption></figure><p>Both these commands are checking the app directory to make sure it is PSR2 compliant. The second command will fix issues if it detects them.</p><h3>Deploying to DigitalOcean</h3><p>Now that we know all of our tests passed and our code is PSR2 compliant we can deploy our updates to DigitalOcean. For the sake of this article I will assume you have your server provisioned and setup. If you need help this article is very helpful: <a href="https://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04">https://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04</a></p><p>Head back to the pipeline and again click the plus sign below the PHP CodeSniffer action. Choose DigitalOcean from “DEPLOY TO IAAS” section.</p><p>It will ask you to login to your DigitalOcean account. Once logged in choose your repository for the “Source” and leave “Source Path” as is. Choose your DigitalOcean account and the droplet you would like to deploy to. For authentication mode choose “Buddy’s SSH Key”. Next login to your droplet via your terminal and run the commands that were given to you to add Buddy’s SSH Key to your droplet. Once you have done this click “Test” at the bottom. If everything works correctly buddy should be able to connect to your droplet. Once connected to your droplet you can browse for the remote path. Most likely the remote path is going to be /var/www/html/yoursitedirectory but this may vary depending on how your droplet is setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iyIJKNMNArQX-6FxrBM1jg.png" /></figure><h3>Installing Composer Packages and Migrating Tables</h3><p>Now that updates have been deployed we need to install any new composer packages and migrate the database incase any new migrations were deployed. Head back to the pipeline and click the plus below the DigitalOcean action. Choose “SSH” from “DEVOPS”. For “SSH Commands” enter</p><pre>composer install --no-interaction --prefer-dist --optimize-autoloader<br>php artisan migrate --force</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLIjM0DaU5yzN8S09L6dsQ.png" /></figure><p>Then below, enter the IP address of your droplet and the username you use to login to your droplet. For “Authentication mode” again choose “Buddy’s SSH key”. Since you already added this SSH key in the previous step you should be all good to go! Change the “Working Directory” to the same directory used for “Remote Path” in the previous step (most likely /var/www/html/yoursitedirectory ) and save the action.</p><h3>Wrapping Up</h3><p>When your done the pipeline should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RgcKFuBmN0J7O58aocnHBA.png" /><figcaption>Finished deployment pipeline</figcaption></figure><p>This deployment pipeline has worked well for me, but feel free to let me know if there are any other actions or tweaks that can be made to improve how it works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=341c95e7fce1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Quick Snippet — body class based on view name]]></title>
            <link>https://medium.com/@petehegman/laravel-quick-snippet-body-class-based-on-view-name-e5b812d02799?source=rss-d89afb154d30------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5b812d02799</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[laravel-5]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[snippet]]></category>
            <dc:creator><![CDATA[Pete Hegman]]></dc:creator>
            <pubDate>Tue, 28 Nov 2017 04:04:40 GMT</pubDate>
            <atom:updated>2017-11-28T04:04:40.588Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e1b3e6374e7b018f665bce9a7d6712a/href">https://medium.com/media/5e1b3e6374e7b018f665bce9a7d6712a/href</a></iframe><p>Lets break this down quickly…</p><p>Start in App\Providers\AppServiceProvider.php . Using the View facade we can pass * to the composer method so that it will be called when any view is rendered. We can then use the the share method to pass the variable viewName to all views that are rendered by your application. To get the view name we call the name() method on $view object passed through the Closure. The name() method will return the view name using “Dot” notation to reference any nested views so we convert any “Dots” to dashes using the built in <a href="http://php.net/manual/en/function.str-replace.php">str_replace</a> PHP function.</p><p>Now in your app.blade.php file we can print out this class in the body tag like so: &lt;body class=&quot;{{ $viewName }}&quot;&gt;</p><p>I find this trick helpful when you need to modify your app layout for a one-off view. For example I recently ran into a situation where I had a page-content wrapper that had padding-top: 50px . This was great for most of my views but one view had a banner image that I wanted flush with the navigation. This trick allowed me to target this view using the above trick and easily remove the unwanted padding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5b812d02799" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Passing CSS breakpoints to Javascript]]></title>
            <link>https://medium.com/@petehegman/passing-css-breakpoints-to-javascript-5896e0df1983?source=rss-d89afb154d30------2</link>
            <guid isPermaLink="false">https://medium.com/p/5896e0df1983</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[bootstrap]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[scss]]></category>
            <category><![CDATA[sass]]></category>
            <dc:creator><![CDATA[Pete Hegman]]></dc:creator>
            <pubDate>Sun, 03 Sep 2017 18:35:46 GMT</pubDate>
            <atom:updated>2017-09-03T18:35:46.021Z</atom:updated>
            <content:encoded><![CDATA[<p>Patching together a few stack overflow threads and other articles I found a pretty cool (and I think fairly clean) way to pass CSS breakpoints to Javascript. Now why would you want to do this? I have run into a few situations where I want some Javascript to run on mobile, but not desktop. You could use a Javascript library to detect what kind of device is being used but I liked the idea of using my CSS breakpoints instead. You could also hardcode the breakpoint into your Javascript, but then if you change it in your css (or sass) file you have to remember to do it in your Javascript file as well.</p><p>The most useful situation I have used this for is animating the dropdown menu on the Bootstrap navbar. I wanted to have a slide effect on the mobile dropdown, but not the desktop. Here is how it works:</p><h4>Your HTML</h4><p>Your basic Bootstrap navbar</p><pre>&lt;nav class=&quot;navbar navbar-default&quot;&gt;<br>    &lt;div class=&quot;container-fluid&quot;&gt;<br>        &lt;!-- Brand and toggle get grouped for better mobile display --&gt;<br>        &lt;div class=&quot;navbar-header&quot;&gt;<br>            &lt;button type=&quot;button&quot; class=&quot;navbar-toggle collapsed&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#bs-example-navbar-collapse-1&quot; aria-expanded=&quot;false&quot;&gt;<br>                &lt;span class=&quot;sr-only&quot;&gt;Toggle navigation&lt;/span&gt;<br>                &lt;span class=&quot;icon-bar&quot;&gt;&lt;/span&gt;<br>                &lt;span class=&quot;icon-bar&quot;&gt;&lt;/span&gt;<br>                &lt;span class=&quot;icon-bar&quot;&gt;&lt;/span&gt;<br>            &lt;/button&gt;<br>            &lt;a class=&quot;navbar-brand&quot; href=&quot;#&quot;&gt;Brand&lt;/a&gt;<br>        &lt;/div&gt;<br>        &lt;!-- Collect the nav links, forms, and other content for toggling --&gt;<br>        &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;bs-example-navbar-collapse-1&quot;&gt;<br>            &lt;ul class=&quot;nav navbar-nav&quot;&gt;<br>                &lt;li class=&quot;active&quot;&gt;&lt;a href=&quot;#&quot;&gt;Link &lt;span class=&quot;sr-only&quot;&gt;(current)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;<br>                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Link&lt;/a&gt;&lt;/li&gt;<br>                &lt;li class=&quot;dropdown&quot;&gt;<br>                    &lt;a href=&quot;#&quot; class=&quot;dropdown-toggle&quot; data-toggle=&quot;dropdown&quot; role=&quot;button&quot; aria-haspopup=&quot;true&quot; aria-expanded=&quot;false&quot;&gt;Dropdown &lt;span class=&quot;caret&quot;&gt;&lt;/span&gt;&lt;/a&gt;<br>                    &lt;ul class=&quot;dropdown-menu&quot;&gt;<br>                        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Action&lt;/a&gt;&lt;/li&gt;<br>                        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Another action&lt;/a&gt;&lt;/li&gt;<br>                        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Something else here&lt;/a&gt;&lt;/li&gt;<br>                        &lt;li role=&quot;separator&quot; class=&quot;divider&quot;&gt;&lt;/li&gt;<br>                        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;Separated link&lt;/a&gt;&lt;/li&gt;<br>                        &lt;li role=&quot;separator&quot; class=&quot;divider&quot;&gt;&lt;/li&gt;<br>                        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;One more separated link&lt;/a&gt;&lt;/li&gt;<br>                    &lt;/ul&gt;<br>                &lt;/li&gt;<br>            &lt;/ul&gt;<br>        &lt;/div&gt;<br>        &lt;!-- /.navbar-collapse --&gt;<br>    &lt;/div&gt;<br>    &lt;!-- /.container-fluid --&gt;<br>&lt;/nav&gt;</pre><h4>Your Sass</h4><p>Create an after pseudo-element on the navigation element where the content changes at the grid-float-breakpoint . If you are not familiar with grid-float-breakpoint it is the breakpoint at which the menu collapses. You can change this variable to adjust when the nav collapses.</p><pre>.navbar {<br>    &amp;::after {<br>        content: &#39;mobile-navigation&#39;;<br>        display: none;</pre><pre>        @media screen and (min-width: $grid-float-breakpoint) {<br>            content: &#39;desktop-navigation&#39;;<br>        }<br>    }<br>}</pre><h4>Your Javascript</h4><p>You can now use the following to get the value of the after pseudo-element.</p><pre>window.getComputedStyle(<br>    document.querySelector(&#39;.site-header&#39;), &#39;:after&#39;<br>).getPropertyValue(&#39;content&#39;).replace(/[&quot;&#39;]/g, &#39;&#39;);</pre><p>What this is doing is it grabbing the content of the after pseudo-element and stripping out double and single quotes (this helps with browser compatibility). Then we can check the content before running code. Below is an example of how to use it to animate the mobile dropdown. Adapted from here: <a href="https://stackoverflow.com/questions/12115833/adding-a-slide-effect-to-bootstrap-dropdown">https://stackoverflow.com/questions/12115833/adding-a-slide-effect-to-bootstrap-dropdown</a></p><pre>$(&#39;.dropdown&#39;).on(&#39;show.bs.dropdown&#39;, function(e) {<br>    var animationCheck = window.getComputedStyle(<br>        document.querySelector(&#39;.site-header&#39;), &#39;:after&#39;<br>    ).getPropertyValue(&#39;content&#39;).replace(/[&quot;&#39;]/g, &#39;&#39;);</pre><pre>if (animationCheck == &#39;mobile-navigation&#39;) {<br>        $(this).find(&#39;.dropdown-menu&#39;).first().stop(true, true).slideDown(300);<br>    }<br>});</pre><pre>$(&#39;.dropdown&#39;).on(&#39;hide.bs.dropdown&#39;, function(e) {<br>    var animationCheck = window.getComputedStyle(<br>        document.querySelector(&#39;.site-header&#39;), &#39;:after&#39;<br>    ).getPropertyValue(&#39;content&#39;).replace(/[&quot;&#39;]/g, &#39;&#39;);</pre><pre>if (animationCheck == &#39;mobile-navigation&#39;) {<br>        $(this).find(&#39;.sub-menu&#39;).first().stop(true, true).slideUp(200, function() {<br>            $(this).css(&#39;display&#39;, &#39;&#39;);<br>        });<br>    }<br>});</pre><p>This is just one example of how this can be used!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5896e0df1983" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Wordpress Dev Setup/Using Laravel Tools to Improve Your Wordpress Development]]></title>
            <link>https://medium.com/@petehegman/my-wordpress-dev-setup-using-laravel-tools-to-improve-your-wordpress-development-f1b08de02d3d?source=rss-d89afb154d30------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1b08de02d3d</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[wordpress-plugins]]></category>
            <category><![CDATA[wordpress-web-development]]></category>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[wordpress-themes]]></category>
            <dc:creator><![CDATA[Pete Hegman]]></dc:creator>
            <pubDate>Sun, 27 Aug 2017 03:41:16 GMT</pubDate>
            <atom:updated>2018-02-16T00:12:49.449Z</atom:updated>
            <content:encoded><![CDATA[<p>At my job I build custom Wordpress themes and plugins and in my free time I love building projects in Laravel and Vue.js. Laravel is an incredible framework that I personally love working with and it also has a bunch of tools that are flexible enough to use in other projects. I have integrated some of these tools into my Wordpress development and thought it could be helpful to others to share how I integrate these Laravel tools to speed up Wordpress development.</p><h3>The Famous 5 Minute Install in 2 Minutes</h3><p>With the help of <a href="https://laravel.com/docs/5.4/valet#installation">Laravel Valet</a> you can easily setup a fresh Wordpress install on your localhost in less than 2 minutes. Below are the steps to getting all of this setup.</p><p><strong>Step 1: Install Laravel Valet</strong></p><p>If you don’t already have <a href="https://brew.sh/">Homebrew</a> install it! Its as simple as opening up your terminal and running /usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;</p><p>Once Homebrew is installed we need to install PHP 7.1 by running brew install homebrew/php/php71</p><p>Next we can install Valet via <a href="https://getcomposer.org/">Composer</a>. If you don’t have <a href="https://getcomposer.org/">Composer</a> you can install it by running the following commands: <a href="https://getcomposer.org/download/">https://getcomposer.org/download/</a><br>Once installed you will want to move the composer.phar file into your bin directory so it can be run globally. To do this run mv composer.phar /usr/local/bin/composer . You may need to run this with sudo depending on permissions. Finally in your terminal run export PATH=”$PATH:~/.composer/vendor/bin”</p><p>Once Composer is installed run composer global require laravel/valet and then valet install to install Valet. Great, Laravel Valet is installed!</p><p>Finally we need a MySQL server. Run brew install mysql</p><p>Lets get Valet and the MySQL server up and running. First make sure you don’t have any other local servers running (MAMP). Then run valet start to start Valet and brew services start mysql to start your MySQL server.</p><p><strong>Step 2: WP CLI</strong></p><p>I like to use the <a href="http://wp-cli.org/">Wordpress Command Line Interface</a> to quickly download a fresh copy of Wordpress. To install this run curl -O <a href="https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar">https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar</a> to download the CLI and then run chmod +x wp-cli.phar` and `sudo mv wp-cli.phar /usr/local/bin/wp to update the permissions and allow it to be run globally.</p><p><strong>Step 3: Folder Structure</strong></p><p>The best way to use Valet is to have all of your sites in one central folder. I like to use the Sites folder in my root directory. Out of the box OSX doesn’t have this folder but it is as easy as running mkdir Sites in your terminal. Now all of your sites can live in this directory.</p><p><strong>Step 4: Putting it all together</strong></p><p>Lets combine all of these tools to see how easy it is to get a fresh Wordpress install up and running.</p><p>First lets “park” Valet. Open up your terminal and run cd Sites and then run valet park . Now every folder in your Sites directory has its own development url out of the box.</p><p>Create a new folder in your Sites directory by running mkdir my-cool-site and then cd into this by running cd my-cool-site</p><p>Run wp core download to download a fresh copy of Wordpress</p><p>Now we need to create a database. I like to use <a href="https://www.sequelpro.com/">Sequel Pro</a> for this step. Open up Sequel Pro and enter 127.0.0.1 for the host and root for the username, then click “Connect”. In the top left click “Choose Database” and then “Add Database”. Enter your database name, I like to keep it the same as the folder for consistency, and click “Add”</p><p>Now, in your browser, navigate to my-cool-site.dev (or the name of your folder followed by .dev) and you should see the start of the Wordpress install. Choose your language and then on the next page enter the name of the database we just made, `root` for the username and leave the password blank. Finish the install and thats it!</p><p>The real beauty of Valet is as you start to get more and more sites on your localhost they are incredibly easy to switch between. They are all available at your-folder-name.dev</p><h3>Compiling Assets With Laravel Mix</h3><p>If your building themes or plugins from scratch you are going to need some sort of build script to compile your Sass and JS. There are lots of tools out there including Gulp, Grunt, Webpack, CodeKit, etc. Before <a href="https://laravel.com/docs/5.4/mix">Laravel Mix</a> (and <a href="https://laravel.com/docs/5.3/elixir">Laravel Elixir</a>) I had a Gulp or Grunt file that I would use between projects, but it was complicated and hard to understand and thats where Laravel Mix is awesome. Laravel Mix is built on top of Webpack and provides a fluent API for defining build tasks.</p><p><strong>Using Laravel Mix in your theme or plugin</strong></p><p>To get started using Mix in your theme or plugin your first need NPM or Yarn. I would suggest using Yarn as it is essentially a substitute for NPM that is much faster and more efficient. You can install Yarn via Homebrew by running brew install yarn</p><p>Then cd into your theme or plugin and if you don’t already have a package.json file run yarn init. Follow the prompts to create a package.json file.</p><p>We need to install two packages to get Mix up and running. Run yarn add laravel-mix and yarn add cross-env</p><p>Next we need to add some scripts to the package.json file. Open this up in your favorite text editor (I use Sublime) and add the following lines to the scripts section:</p><pre>“dev”: “yarn run development”,<br> “development”: “cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js — progress — hide-modules — config=node_modules/laravel-mix/setup/webpack.config.js”,<br> “watch”: “cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js — watch — progress — hide-modules — config=node_modules/laravel-mix/setup/webpack.config.js”,<br> “watch-poll”: “yarn run watch — — watch-poll”,<br> “hot”: “cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js — inline — hot — config=node_modules/laravel-mix/setup/webpack.config.js”,<br> “prod”: “yarn run production”,<br> “production”: “cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js — progress — hide-modules — config=node_modules/laravel-mix/setup/webpack.config.js”</pre><p>Next we need to create our configuration file. Create a file named webpack.mix.js in the root of your theme or plugin. In this file add the following:</p><pre>let mix = require(‘laravel-mix’);</pre><pre>/*<br> | — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — <br> | Mix Asset Management<br> | — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — <br> |<br> | Mix provides a clean, fluent API for defining some Webpack build steps<br> | for your Laravel application. By default, we are compiling the Sass<br> | file for the application as well as bundling up all the JS files.<br> |<br> */</pre><pre>mix.js(‘src/js/app.js’, ‘public/js’)<br> .sass(‘src/sass/app.scss’, ‘public/css’)<br> .browserSync({<br> proxy: ‘your-cool-site.dev’<br> });</pre><p>The above example will compile `app.js` and place it in the public/js directory. It will compile app.scss down and place it in the public/css directory, and it will use <a href="https://www.browsersync.io/">BrowserSync</a> to live reload when running the watch command. Of course these paths can be changed and the full documentation for defining tasks can be found here: <a href="https://laravel.com/docs/5.4/mix">https://laravel.com/docs/5.4/mix</a></p><p><strong>Compiling Assets</strong></p><p>Once you have the above all setup you can run yarn run dev to compile assets down. Run yarn run prod to compile and minify assets, and run yarn run watch to watch Sass and JS files for changes and compile them down.</p><h3>Using dd() in Wordpress Development</h3><p>If you have used Laravel before you know about dd() . It is a simple yet very helpful function to dump an object or array in a readable format and then end the script execution. I found this function so helpful that I built a very simple plugin to allow you to use it when developing Wordpress themes or plugins. All you have to do is install <a href="https://wordpress.org/plugins/laravel-dd/">https://wordpress.org/plugins/laravel-dd/</a>, activate it and you can use dd() in any theme or plugin.</p><p>Since I only really need this plugin on my localhost during development and I use git for deployment I like to add wp-content/plugins/laravel-dd/ to my .gitignore</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1b08de02d3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>