<?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 James Fairhurst on Medium]]></title>
        <description><![CDATA[Stories by James Fairhurst on Medium]]></description>
        <link>https://medium.com/@james_fairhurst?source=rss-b5a7cf9a0909------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0trv2ja2l8wZdQqW.png</url>
            <title>Stories by James Fairhurst on Medium</title>
            <link>https://medium.com/@james_fairhurst?source=rss-b5a7cf9a0909------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:52:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@james_fairhurst/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[Serving 404s for Old Blog Posts with NGINX on Laravel Forge]]></title>
            <link>https://medium.com/@james_fairhurst/serving-404s-for-old-blog-posts-with-nginx-on-laravel-forge-c40392775c72?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/c40392775c72</guid>
            <category><![CDATA[laravel-forge]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 08:21:28 GMT</pubDate>
            <atom:updated>2019-04-12T08:21:28.751Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/serving-404s-for-old-blog-posts-with-nginx-on-laravel-forge"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><p>Previously my old site hosted quite a number of really old blog posts, most recent was 2013 with the majority in 2008 when I was primarily developing in CakePHP. I wanted a clean slate (as do all devs!) so decided not to port them over or bother with creating an archive. By default on Forge when setting up SSL everything gets redirected to it’s <strong>https</strong> counterpart, for old blog posts the initial server response was a 301 redirect (http -&gt; https) then a 404 as the page wasn’t found.</p><p>To keep things clean and indicate to Google that those pages have been removed I wanted to immediately serve a 404. I did something similar to <a href="https://www.jamesfairhurst.co.uk/serving-404s-for-old-subdomains-with-nginx-on-laravel-forge">serve 404s for old subdomains</a> so using the same custom <strong>before</strong> config file I added a new server block for a specific post:</p><pre>server {<br>    listen 80;<br>    listen [::]:80;<br><br>    server_name .jamesfairhurst.co.uk;<br>    location = /posts/view/old_post_url {<br>       return 404;<br>    }<br>}</pre><p>This worked however it broke other page redirects it should have caught, I found a <a href="https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms">great article</a> detailing server &amp; location blocks which was super handy not being too familiar with nginx. Using the ^~ modifier caught all /posts/view/* urls and I also needed to add the / location block as a fallback for http -&gt; https redirects taken from Forge&#39;s ssl_redirect.conf file.</p><pre>server {<br>    listen 80;<br>    listen [::]:80;<br><br>    server_name .jamesfairhurst.co.uk;<br><br>    location ^~ /posts/view {<br>        return 404;<br>    }<br><br>    location / {<br>        return 301 https://$host$request_uri;<br>    }<br>}</pre><p>After making changes run sudo service nginx reload to make the new changes active, and finally test the urls either in the browser or be fancy and use the command line. Instead of cURL I&#39;ve been using <a href="https://httpie.org/">HTTPie</a> which is a super nice command line HTTP client:</p><pre>[jamesfairhurst:~]$ http --headers http://www.jamesfairhurst.co.uk/posts/view/old_post_url<br>HTTP/1.1 404 Not Found<br>Connection: keep-alive<br>Content-Length: 153<br>Content-Type: text/html<br>Date: Thu, 11 Apr 2019 08:34:20 GMT<br>Server: nginx/1.15.8</pre><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/serving-404s-for-old-blog-posts-with-nginx-on-laravel-forge"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c40392775c72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Splitting Out Log Levels With Laravel]]></title>
            <link>https://medium.com/@james_fairhurst/splitting-out-log-levels-with-laravel-871d62caf860?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/871d62caf860</guid>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Fri, 12 Apr 2019 00:00:00 GMT</pubDate>
            <atom:updated>2019-10-10T13:02:43.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJAxF4F2GDiE5SJIUJPBZQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@impatrickt?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Patrick Tomasso</a> on <a href="https://unsplash.com/s/photos/log-split?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>If you’re using <strong>Laravel 5.5 or below</strong> my <a href="https://medium.com/@james_fairhurst/configuring-multiple-laravel-log-files-a1ad1895e0e4">old medium article</a> may be what you’re after. The following will only work in recent versions.</p><p>The <a href="https://github.com/Seldaek/monolog">Monolog</a> logging library that Laravel uses is really quite powerful, like most things in the framework it works flawlessly out of the box and unless you want to do something specific you may not need to investigate how it works.</p><p>I previously wrote an article for old versions of Laravel detailing using multiple log files which kind of worked, but I wanted to revisit and see if things have changed in newer versions.</p><p>Say you wanted to split out log levels into their own files e.g. debug.log, info.log etc — Looking at the <a href="https://laravel.com/docs/5.8/logging#creating-monolog-handler-channels">docs</a> it’s possible to use a many number of different <a href="https://github.com/Seldaek/monolog/blob/master/doc/02-handlers-formatters-processors.md">handlers</a> that Monolog provide. Delving into this I discovered the <a href="https://github.com/Seldaek/monolog/blob/master/src/Monolog/Handler/FilterHandler.php">FilterHandler</a> which can be used to only log specific levels. Just want we want!</p><p>So we create a new channel, set the driver to monolog and the handler to Monolog\Handler\FilterHandler::class, we can then pass in the constructor arguments using handler_with. As the first param is the handler we need to instantiate it at the top as we&#39;re currently in an array. Next specify the level(s) we want to log with minLevelOrList. If you wanted a range of levels you can provide a min level here and also pass a maxLevel as the 3rd param. Finally add the channel name to the list of channels in the stack channel so that it will be used.</p><pre>config/logging.php<br><br>&lt;?php<br><br>use Monolog\Handler\StreamHandler;<br>use Monolog\Handler\SyslogUdpHandler;<br><br>$infoStreamHander = new StreamHandler(storage_path(&#39;logs/info.log&#39;));<br>$errorStreamHander = new StreamHandler(storage_path(&#39;logs/error.log&#39;));<br><br>...<br><br>return [<br>    &#39;channels&#39; =&gt; [ <br>        &#39;stack&#39; =&gt; [<br>            &#39;driver&#39; =&gt; &#39;stack&#39;,<br>            &#39;channels&#39; =&gt; [&#39;daily&#39;, &#39;info&#39;, &#39;error&#39;],<br>        ],<br><br>        ...<br><br>        &#39;info&#39; =&gt; [<br>            &#39;driver&#39;  =&gt; &#39;monolog&#39;,<br>            &#39;handler&#39; =&gt; Monolog\Handler\FilterHandler::class,<br>            &#39;handler_with&#39; =&gt; [<br>                &#39;handler&#39; =&gt; $infoStreamHander,<br>                &#39;minLevelOrList&#39; =&gt; [Monolog\Logger::INFO],<br>            ],<br>        ],<br><br>        &#39;error&#39; =&gt; [<br>            &#39;driver&#39;  =&gt; &#39;monolog&#39;,<br>            &#39;handler&#39; =&gt; Monolog\Handler\FilterHandler::class,<br>            &#39;handler_with&#39; =&gt; [<br>                &#39;handler&#39; =&gt; $infoStreamHander,<br>                &#39;minLevelOrList&#39; =&gt; [Monolog\Logger::ERROR],<br>            ],<br>        ],<br><br>        ...<br>    ]<br>];</pre><p>Test by using the various Log methods to output the full range of error messages you’re likely to see and behold, only the levels you specified will come through to the different log files.</p><pre>Illuminate\Support\Facades\Log::debug(&#39;debug&#39;);<br>Illuminate\Support\Facades\Log::info(&#39;info&#39;);<br>Illuminate\Support\Facades\Log::notice(&#39;notice&#39;);<br>Illuminate\Support\Facades\Log::warning(&#39;warning&#39;);<br>Illuminate\Support\Facades\Log::error(&#39;error&#39;);<br>Illuminate\Support\Facades\Log::critical(&#39;critical&#39;);<br>Illuminate\Support\Facades\Log::alert(&#39;alert&#39;);<br>Illuminate\Support\Facades\Log::emergency(&#39;emergency&#39;);</pre><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/splitting-out-log-levels-with-laravel"><em>https://www.jamesfairhurst.co.uk</em></a><em> on April 12, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=871d62caf860" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Dynamic SVG Image with Laravel]]></title>
            <link>https://medium.com/@james_fairhurst/creating-a-dynamic-svg-image-with-laravel-7ce9454af51b?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ce9454af51b</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Fri, 05 Apr 2019 08:08:38 GMT</pubDate>
            <atom:updated>2019-04-05T08:08:38.801Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B3jcJCGzws5CDArU4H5Q9w.png" /></figure><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/creating-a-dynamic-svg-image-with-laravel"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><p>I really like the svg image in the header of the blog, it was taken from <a href="https://svgbackgrounds.com/">SVG Backgrounds</a> and I thought it would be quite cool to try to animate it by updating the colours to convey some sort of wave. It’s not animation as such as it isn’t using CSS to move things but I did want to cycle through the colours.</p><p>I first mapped out the colours used $colours = [&#39;364347&#39;,&#39;465256&#39;,&#39;566164&#39;,&#39;667073&#39;,&#39;767F82&#39;,&#39;868E91&#39;,&#39;969D9F&#39;,&#39;A7ACAE&#39;,&#39;B7BBBD&#39;,&#39;C7CACB&#39;]; in an array so that I could cycle through them, moving the first colour to the back of the array in an attempt to create motion.</p><p>I then created a new route which will act as the dynamic svg image and point that a controller. With Laravel you can take control of the status &amp; headers using <a href="https://laravel.com/docs/5.8/responses#view-responses">View Responses</a> so that you can set the <strong>Content-Type</strong> so that the browser sees it as an svg:</p><pre>Route::get(&#39;/main-header.svg&#39;, &#39;SvgController@show&#39;);<br><br>function show()<br>{<br>    ...<br>    return response()<br>        -&gt;view(&#39;svg&#39;, [<br>            &#39;colours&#39; =&gt; $colours<br>        ], 200)<br>        -&gt;header(&#39;Content-Type&#39;, &#39;image/svg+xml&#39;);<br>}</pre><p>The blade template is simply the raw svg image but now we can use our $colours array to specify the fill colours of the different waves:</p><pre>&lt;svg xmlns=&#39;http://www.w3.org/2000/svg&#39; width=&#39;100%&#39; height=&#39;100%&#39; viewBox=&#39;0 0 1600 800&#39;&gt;<br>  &lt;rect fill=&#39;#ffaa00&#39; width=&#39;1600&#39; height=&#39;800&#39;/&gt;&lt;g&gt;<br>  &lt;path fill=&#39;#{{ $colours[0] }}&#39; d=&#39;M486 705.8c-109.3-21.8-223.4-32.2-335.3-19.4C99.5 692.1 49 703 0 719.8V800h843.8c-115.9-33.2-230.8-68.1-347.6-92.2C492.8 707.1 489.4 706.5 486 705.8z&#39;/&gt;<br>  &lt;path fill=&#39;#{{ $colours[1] }}&#39; d=&#39;M1600 0H0v719.8c49-16.8 99.5-27.8 150.7-33.5c111.9-12.7 226-2.4 335.3 19.4c3.4 0.7 6.8 1.4 10.2 2c116.8 24 231.7 59 347.6 92.2H1600V0z&#39;/&gt;<br>  ...<br>  &lt;/g&gt;<br>&lt;/svg&gt;</pre><p>In order to make it dynamic I’m using a simple query param to change the index of colours and do some array slicing to move them from the back to the front. e.g. /main-header.svg?i=1, /main-header.svg?i=2 etc</p><pre>array_merge(array_slice($colours, $request-&gt;query(&#39;i&#39;, 0)*-1), array_slice($colours, 0, count($colours)-$request-&gt;query(&#39;i&#39;, 0)))</pre><p>Finally a little Javascript is needed to set an interval which will load and update the next image in the sequence and update the css. Initially I was just saving the image src in the loaded array however the browser was re-loading previously displayed images for some reason and there was a slight flash of black as the background-image was set. Saving the entire image object and using that seems to resolve the issue.</p><pre>var intervalID = window.setInterval(animateHeaderBackgroundSvgImage, 500);<br>var counter = 1;<br>var loaded = [];<br><br>function animateHeaderBackgroundSvgImage() {<br>    // Reset counter<br>    if (counter &gt;= 10) {<br>        counter = 0;<br>    }<br><br>    const alreadyLoaded = loaded.filter(img =&gt; img.src == window.location.origin+&#39;/main-header.svg?i=&#39;+counter);<br><br>    // Image has already been loaded so just update the css<br>    if (alreadyLoaded.length) {<br>        document.getElementById(&#39;main-header&#39;).style.backgroundImage = &#39;url(https://medium.com/&#39;+alreadyLoaded[0].src+&#39;)&#39;;<br>    } else {<br>        // Load the next image in the sequence and update the css when fully loaded<br>        img = new Image();<br>        img.onload = function () {<br>            loaded.push(this);<br>            document.getElementById(&#39;main-header&#39;).style.backgroundImage = &#39;url(https://medium.com/&#39;+this.src+&#39;)&#39;;<br>        };<br>        img.src = window.location.origin+&#39;/main-header.svg?i=&#39;+counter;<br>    }<br><br>    counter++;<br>}</pre><p>Although a nice experiment I didn’t really like the final animation enough to deploy it everywhere so I’ve just enabled it for this post but thought a write up would be useful.</p><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/creating-a-dynamic-svg-image-with-laravel"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ce9454af51b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tracking Pageviews Server Side with Google Analytics and Laravel]]></title>
            <link>https://medium.com/@james_fairhurst/tracking-pageviews-server-side-with-google-analytics-and-laravel-525a64e11ee0?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/525a64e11ee0</guid>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Fri, 29 Mar 2019 08:25:41 GMT</pubDate>
            <atom:updated>2019-03-29T08:25:41.098Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/tracking-pageviews-server-side-using-google-analytics-and-laravel"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><p>Wanting to use as little JavaScript as possible on my new site I didn’t want to go down the traditional route of adding Google’s global site tag (gtag.js) or Google Tag Manager — it feels a bit dirty these days and I personally use <a href="https://www.ghostery.com/">Ghostery</a> to block everything anyway. Perhaps a bit hypocritical of me but I did still want to know what pages are being seen the most. I looked into a few privacy focused analytics services but in the end wanted todo something server side so that it didn’t impose on the front end.</p><p>After a little digging I came across <a href="https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide">Google’s Measurement Protocol</a> that allows you to send HTTP requests for common hit types e.g. <a href="https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#page">pageviews</a>! which appears to do exactly what I’m after. A server side, simple page tracking service with the bonus of using the existing Analytics dashboard.</p><h3>Initial Thoughts</h3><p>Initially I thought some form of Middleware would be a good idea however it’s a blaring bottleneck as the site will have to wait for the HTTP request to serve actual requests. Technically I guess it could be done by using queues to defer the request but it’s an overhead I didn’t want to implement. I’m also using the <a href="https://github.com/spatie/laravel-responsecache">spatie/laravel-responsecache</a> package to cache page responses so not sure it would play nice.</p><p>Eventually I succumbed to a tiny bit of plain Javascript to send an <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send#Example_POST">XMLHttpRequest</a> request with the bare minimum to record a pageview:</p><pre>var xhr = new XMLHttpRequest();<br><br>xhr.open(&quot;POST&quot;, &#39;{{ route(&#39;pageviews.store&#39;) }}&#39;, true);<br><br>xhr.setRequestHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);<br><br>xhr.send(&quot;_token={{ csrf_token() }}&amp;dp={{ urlencode(request()-&gt;getRequestUri()) }}&amp;dt={{ urlencode(app(&#39;view&#39;)-&gt;yieldContent(&#39;title&#39;)) }}&amp;ua={{ urlencode(request()-&gt;header(&#39;user-agent&#39;)) }}&amp;dr={{ urlencode(url()-&gt;previous()) }}&quot;);</pre><p>A few things to note, I’m sending the <strong>csrf token</strong> so that it doesn’t get blocked by Laravel’s <strong>VerifyCsrfToken</strong> middleware, you could allow it via the $except variable but I&#39;ve chosen not to.</p><p>The controller code is pretty straight forward, a post request to https://www.google-analytics.com/collect using the GuzzleHttp library with the <a href="https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#page">bare parameters</a>:</p><pre>use GuzzleHttp\Client;<br><br>$client = new Client([&#39;base_uri&#39; =&gt; &#39;https://www.google-analytics.com/&#39;]);<br><br>try {<br>    $response = $client-&gt;post(&#39;collect&#39;, [<br>        &#39;query&#39; =&gt; array_merge($request-&gt;only([&#39;dp&#39;, &#39;dt&#39;, &#39;ua&#39;, &#39;dr&#39;]), [<br>            &#39;v&#39; =&gt; &#39;1&#39;,<br>            &#39;t&#39; =&gt; &#39;pageview&#39;,<br>            &#39;tid&#39; =&gt; &#39;UA-xxx&#39;,<br>            &#39;cid&#39; =&gt; &#39;555&#39;,<br>            &#39;dh&#39; =&gt; config(&#39;app.url&#39;),<br>        ])<br>    ]);<br>}</pre><p>The response you get is usually always a 200 so to validate you can either use their <a href="https://developers.google.com/analytics/devguides/collection/protocol/v1/validating-hits">debug url</a> or as I did open the real-time dashboard to ensure that your hits are coming through.</p><h3>Creating a Laravel Package</h3><p>I recently bought the <a href="https://phppackagedevelopment.com/">PHP Package Development</a> course from <a href="https://twitter.com/marcelpociot">Marcel</a> which is great and it gave me a kick in the arse to create my own simple package that can be easily used across projects.</p><p>I used a few of <a href="https://github.com/spatie">Spatie’s packages</a> for inspiration and general organisation so I present <a href="https://github.com/jamesfairhurst/laravel-google-analytics-pageviews">jamesfairhurst/laravel-google-analytics-pageviews</a> which you can use to easily track your pageviews in a Laravel application.</p><p>Install the package composer require jamesfairhurst/laravel-google-analytics-pageviews add your Google Analytics tracking id as an .env variable named PAGEVIEWS_GOOGLE_ANALYTICS_TRACKING_ID and finally add the @pageviews blade directive before the closing body tag. Simples!</p><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/tracking-pageviews-server-side-using-google-analytics-and-laravel"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=525a64e11ee0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serving 404s for Old Subdomains with NGINX on Laravel Forge]]></title>
            <link>https://medium.com/@james_fairhurst/serving-404s-for-old-subdomains-with-nginx-on-laravel-forge-85e941628275?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/85e941628275</guid>
            <category><![CDATA[laravel-forge]]></category>
            <category><![CDATA[nginx]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Fri, 22 Mar 2019 12:08:46 GMT</pubDate>
            <atom:updated>2019-03-22T12:08:46.605Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/serving-404s-for-old-subdomains-with-nginx-on-laravel-forge"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><p>Previously my old site hosted quite a number of subdomains for old projects and scripts, when moving to Laravel Forge and setting up SSL everything now gets redirected. I wanted to serve 404s for those old subdomains as it’s more of a correct response than a 301 to the homepage.</p><p>I’m not familiar with NGINX but the configs are nice and clean, Forge uses a before include which has a ssl_redirect.conf file which deals with redirecting non https traffic to it&#39;s https counterpart.</p><pre># FORGE CONFIG (DO NOT REMOVE!)</pre><pre>include forge-conf/www.example.co.uk/before/*;</pre><pre>server {<br>...</pre><p>I created a new file in the /etc/nginx/forge-conf/www.example.co.uk/before/ directory that listens for specific subdomains and simply returns a default 404 response. I named that file a.conf to ensure that it loads before any existing conf files.</p><pre>server {<br>  listen 80;<br>  listen [::]:80;<br>  server_name a.example.co.uk b.example.co.uk;<br>  return 404;<br>}</pre><p>Finally restart NGINX (in the Forge admin) to ensure that the new config file comes into play and voila!</p><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/serving-404s-for-old-subdomains-with-nginx-on-laravel-forge"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85e941628275" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Importing Your Blog Posts into Medium]]></title>
            <link>https://medium.com/@james_fairhurst/importing-your-blog-posts-into-medium-f8e4bf00ab80?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8e4bf00ab80</guid>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[blogging]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Fri, 15 Mar 2019 09:40:10 GMT</pubDate>
            <atom:updated>2019-03-15T09:40:10.215Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/importing-your-blog-posts-into-medium"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><p>Medium is a great place for content, combined with the lovely easy interface for writing it seemed a great place to put all your publications. As they’ve grown and started to try to make money (as they should) things have become a little more restrictive. Paid subscriptions, pay walls, etc urgh. It’s not what it used to be and people are moving away. Having said that the reach &amp; exposure of Medium can still be useful and so cross posting is possible and this is how.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*omDZdoQtIk-15aM_Z01F1A.png" /></figure><p><a href="https://help.medium.com/hc/en-us/articles/214550207-Import-post">Importing into Medium</a> is possible, instead of writing a new story there’s an <strong>Import a story</strong> button next to the <strong>Write a story</strong> button on the stories page. Enter your blog post URL and Medium will scrape the post and populate their editor. You’re then free to make changes, add tags, change publication settings and finally publish. The benefit of doing it this way and importing the post rather than posting 2 separate posts is that Medium kindly use a canonical tag pointing to your original post meaning that you won&#39;t be penalised for duplicate content with search engines which is super important!</p><h3>Existing Posts</h3><p><a href="https://twitter.com/dhh">DHH</a> has been vocal regarding Medium in the past and once delighted in moving their <a href="https://m.signalvnoise.com/">Signal v Noise Blog</a> to the platform outlining their reasons <a href="https://m.signalvnoise.com/signal-v--noise-moves-to-medium">here</a>. However they’ve since <a href="https://m.signalvnoise.com/signal-v-noise-exits-medium">moved back</a> at the start of the year and <a href="https://twitter.com/dhh/status/1037101907972505601">recommend against</a> using Medium for new posts (especially as they have stopped supporting custom domains). <a href="https://baremetrics.com/blog/medium-back-to-blog">Others</a> have also moved away and both of those had early custom domain support so migrating away was pain free being able to setup redirects back to their original blogs.</p><p>If you have old Medium posts without the custom domain, as I do, things are bit more tricky. You are able to <a href="https://help.medium.com/hc/en-us/articles/115004745787-Download-your-information">export</a> your content but the result is a jumbled mess of HTML files. I saw some Wordpress plugins that you can use to import to a Wordpress blog which is useful <em>if</em> you’re on that platform.</p><p>Currently I’m literally copying &amp; pasting content into my new Markdown format and will gradually publish them here. The issue I have is what todo with existing posts on Medium. At some point in the past it looks like it was possible to <a href="https://blog.rackmaze.com/how-to-create-a-backdated-story-on-medium-47f2d505f9e5">backdate</a> <a href="https://blog.bretthard.in/how-to-backdate-medium-posts-75295f5534ad">posts</a> which doesn’t seem possible now which is frustrating. I’ve reached out to support to see if they can add canonical tags to existing posts pointing back to my post so we&#39;ll see.</p><h3>Strategy</h3><p>For new posts it looks like the best option is to post on your personal blog and then import the post into Medium a few weeks later. Hopefully the search engines will pick up your post first and be given the real good SEO magic juice and then can be picked up on Medium as a cross post for that lovely Medium reach.</p><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/importing-your-blog-posts-into-medium"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8e4bf00ab80" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2019]]></title>
            <link>https://medium.com/@james_fairhurst/2019-e5a7711be374?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5a7711be374</guid>
            <category><![CDATA[blog]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Sat, 02 Mar 2019 21:13:18 GMT</pubDate>
            <atom:updated>2019-03-02T21:13:18.951Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-bPXdpvF8kgddqvnL6UTg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/3LsocYqXWpM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Scott Webb</a> on <a href="https://unsplash.com/search/photos/green-field?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/2019"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><p>Every New Year is a fresh slate, people make resolutions, review the previous year and set intentions on what they want to do this year. I’m no different! My site was very outdated and cringe worthy, last post was in 2013 and things have changed (2 kids happened and tiredness is at 11!) I did intend to get the new site out of the door in January but with client work and a 2 month old baby things didn’t go to plan!</p><blockquote><em>Perfect is the enemy of good</em></blockquote><blockquote><a href="https://en.wikipedia.org/wiki/Perfect_is_the_enemy_of_good"><em>Voltaire</em></a></blockquote><p>Recently I read a <a href="https://vgpena.github.io/good-is-better-than-perfect/">great article</a> about how <strong>good is better than perfect</strong> which sums up my sentiments on creating a new website, there’s always more things I want to do and tweak, this or that isn’t quite right which leads to things never being fully finished or released :( I tried to avoid limit that by building it as an MVP and even then I wasn’t fully satisfied but I don’t think I ever will be so getting it out of the door is a priority and then try to <em>hopefully</em> improve it iteratively each day/week.</p><h3>Development</h3><p>The old site was built using <strong>CakePHP</strong> and a little CSS framework called <a href="http://getskeleton.com/">Skeleton</a>, things move fast and <strong>Laravel</strong> disrupted the PHP ecosystem in a massive way and that’s what’s being used here. I did consider using <a href="https://tailwindcss.com/">Tailwind</a> for the front end framework but settled for <strong>Bootstrap 4</strong> out of familiarity and wanting to get it out of the door as soon as possible. I may revisit Tailwind in the future, it’s getting a lot of attention in the Laravel community and I really like using the utility classes in Bootstrap.</p><h3>CSS</h3><p>I’m using the default <a href="https://laravel.com/docs/5.8/mix">Laravel Mix</a> Webpack setup that comes as default with Laravel, learning Webpack is on my learn list as it’s a bit of a mystery to me currently. Instead of importing all of Bootstrap’s components I’ve been selective and only enabled what I’m using:</p><pre>// Bootstrap <br>// @import &#39;~bootstrap/scss/bootstrap&#39;; <br>@import &quot;~bootstrap/scss/functions&quot;; <br>@import &quot;~bootstrap/scss/variables&quot;; <br>@import &quot;~bootstrap/scss/mixins&quot;; <br>// Optional <br>@import &quot;~bootstrap/scss/root&quot;; <br>// @import &quot;~bootstrap/scss/tables&quot;; ...</pre><p>Colour palette comes from an old <a href="https://dribbble.com/shots/1736664-Free-HTML-PSD-UI-Kit">UI Kit</a> that I’ve always wanted to use on a project, seems the site is down but managed to find the free version on <a href="https://github.com/rikitanone/drunken-parrot-flat-ui">Github</a>. I’ve used those in a <strong>_variables.scss</strong> file before importing Bootstrap and they’ll be used instead of the defaults:</p><pre>// Colors <br>$blue: #02baf2; <br>$indigo: #a88cd5; <br>$purple: #9175bd; <br>$pink: #f66D9b; <br>$red: #f84545; <br>$orange: #f6993f; <br>$yellow: #fad46b; <br>$green: #3eb5ac; <br>$teal: #28948c; <br>$cyan: #3eb5ac; </pre><pre>$primary: $blue; <br>$secondary: $gray-800; <br>$success: $green; <br>$info: $purple; <br>$warning: $yellow; <br>$danger: $red; <br>$light: $gray-100; <br>$dark: $gray-900;</pre><p>Quite powerful and lets you quickly change from the bog standard Bootstrap colours. Checkout the <a href="https://getbootstrap.com/docs/4.3/getting-started/theming/">Bootstrap docs</a> for more info on theming.</p><h4>SVG Header Image</h4><p>One thing I do quite like about the design is the top header background image on the homepage, I used an SVG image from <a href="https://www.svgbackgrounds.com/">SVG Backgrounds</a> and they provide CSS that you can use. I did want to keep theme colours so using SASS I was able to use Bootstrap’s theme-color-level(dark) and shades such as theme-color-level(dark, -1) which is pretty nice. One issue I had is that the # in the colour wasn&#39;t encoded so I had to <a href="https://gist.github.com/certainlyakey/e9c0d8f5c87ff47e3d5b">hunt down</a> a wrapper function that encodes it so now I can use colours like fill=&#39;#{encodecolor(theme-color-level(dark))}&#39; in my SASS file that uses my theme colour in an SVG image (this also uses interpolation with the hash and brackets). Noice.</p><h4>Reducing CSS Size</h4><p>Using Laravel Mix I was able to use <a href="https://github.com/spatie/laravel-mix-purgecss">spatie/laravel-mix-purgecss</a> which does a great job of reducing the size of your CSS file by using <a href="https://www.purgecss.com/">Purgecss</a> to remove all the styles that your views/templates/files don’t use. Installation is pretty easy and works out of the box and I’m seeing a reduction in size from <strong>95.1 KiB</strong> to <strong>17.4 KiB</strong> saving <strong>77.7 KiB</strong>!!</p><h4>Reducing Image Size</h4><p>Laravel Mix doesn’t optimise images out of the box so my searching came up with this <a href="https://github.com/JeffreyWay/laravel-mix/issues/426#issuecomment-287575459">great comment</a> which details how to install <strong>imagemin</strong> and setup webpack to copy and optimise an image folder which works great.</p><pre>mix.webpackConfig({<br>    plugins: [<br>        new CopyWebpackPlugin([{<br>            from: &#39;resources/images&#39;,<br>            to: &#39;img&#39;,<br>        }]),<br>        new ImageminPlugin({<br>            test: /\.(jpe?g|png|gif|svg)$/i,<br>            plugins: [<br>                imageminMozjpeg({<br>                    quality: 80,<br>                })<br>            ]<br>        })<br>    ]<br>});</pre><h3>Javascript</h3><p>I didn’t really want to bring in any frameworks for a simple blog site so I’ve used vanilla JS for the small chunks for functionality where needed and even then it isn’t much. I did initially include <a href="https://fontawesome.com/start">Font Awesome</a> for the 3 icons in the homepage header and couldn’t find an easy way of just pulling in specific ones without integrating them into the build process so just went plain SVG images in the end.</p><p>I have some image lazy loading to make the page load quickly, I just attach the image src as a data attribute and simply loop through them all on window load, create new Image instances, set an onload event handler to set the src on the element (needs to be done before actually setting the image src) and finally set the image instance src to the data attribute src.</p><pre>&lt;img data-src=&quot;<a href="http://example.com/image.jpg">http://example.com/image.jpg</a>&quot;&gt;</pre><pre>window.onload = function () {<br>    document.querySelectorAll(&#39;[data-src]&#39;).forEach(function (el) {<br>        img = new Image();<br>        img.onload = function () {<br>            el.src = this.src;<br>        };<br>        img.src = el.dataset.src;<br>    });<br>};</pre><h3>Packages</h3><p>Just a few packages have been included, it’s a simple site so didn’t need much:</p><pre>&quot;nothingworks/blade-svg&quot;  - for inlining svg images in Blade templates<br>&quot;pagerange/metaparsedown&quot; - for parsing Markdown AND yaml metadata<br>&quot;spatie/laravel-feed&quot;     - for an rss feed<br>&quot;spatie/laravel-honeypot&quot; - for protecting the contact form</pre><p><a href="https://github.com/adamwathan/blade-svg">nothingworks/blade-svg</a></p><p>Super useful for inlining svg images in Blade templates e.g. @svg(&#39;twitter&#39;, &#39;icon&#39;).</p><p><a href="https://github.com/pagerange/metaparsedown">pagerange/metaparsedown</a></p><p>For parsing Markdown <strong>AND</strong> yaml metadata, as mentioned my posts are written using Markdown, Laravel uses the <a href="https://github.com/erusev/parsedown">erusev/parsedown</a> package for emails which is great however I also wanted to include meta data in my posts so that I didn’t have to touch the database for custom things e.g. meta description, header images etc so I found this (which extends the package used by Laravel) for doing both which seems to work well. Allows me to do the following in my files which are then imported via a command:</p><pre>---<br>title: &#39;Hiphopopotamus&#39;<br>meta_description: &#39;Awesome song!&#39;<br>tags: &#39;songs&#39;<br>---<br>Here&#39;s the Hiphopopotamus, The hip hop hippo, They call me the Hiphopopotamus, My lyrics are bottomless...</pre><p><a href="https://github.com/spatie/laravel-feed">spatie/laravel-feed</a></p><p>A quick and easy way to enable an RSS feed to the site. I feel RSS is still one of the best ways to keep upto date with multiple sources, still think about Google Reader R.I.P — now I use <a href="https://feedly.com/">Feedly</a>!</p><p><a href="https://github.com/spatie/laravel-honeypot">spatie/laravel-honeypot</a></p><p>For protecting the contact form from tricksy spamers.</p><h3>Goals</h3><p>I’ve always tried to keep a few goals throughout the year, usually they peter out throughout the year :( so hopefully documenting them publicly will help me keep on track.</p><h3>Meditation</h3><p>I’m always hearing lots about the benefits of meditation, when I sit quietly even for a moment the monkey brain spews out all sorts of things. Meditating can help and I’ve found it does, I’ve been using an app called <a href="https://www.oakmeditation.com/">Oak</a> from <a href="https://www.kevinrose.com/">Kevin Rose</a> which I really like. Simple and I’ve been using the same track each time. Currently on a <strong>62</strong> day streak!</p><h3>Spanish</h3><p>Language learning is good for the brain (apparently) I’ve been <em>learning</em> French since school but seems never to stick and recently switched to Spanish. Tried <strong>Duolingo</strong> but got fed up with them constantly changing the app and gaming it with more hearts blah blah. Now using <a href="https://lingvist.com/">Lingvist</a> to learn words which is working really well, there’s a goal of 100 words a day with the aim of 20 new words. Doing 100 works well but 20 a day is a bit of a stretch. Really need to accompany this with <a href="https://www.michelthomas.com/">Michel Thomas</a> for practical speaking. It’s just finding the time! Currently on a <strong>37</strong> day streak.</p><h3>Reading</h3><p>I love reading, I use <a href="https://www.goodreads.com/user/show/5105476-james">Goodreads</a> to keep track of everything and sign up to their yearly challenges. Missed my 2018 of 35 books by 2 so dropped it to 30 this year, having a toddler and a fresh baby doesn’t give me much time but trying where I can. Highlights of last year include <a href="https://www.goodreads.com/book/show/17934530-annihilation">Annihilation</a>, <a href="https://www.goodreads.com/book/show/33257757-iron-gold">Iron Gold</a>, <a href="https://www.goodreads.com/book/show/31215359-shoe-dog">Shoe Dog</a> &amp; the <a href="https://www.goodreads.com/book/show/68428.The_Final_Empire">Mistborn</a> series.</p><h3>Exercise</h3><p>Working for myself, from home can be pretty sedentary. Picked up an Ikea sit/stand desk last year which is great but working out and lifting heavy things needs to be a priority. I’m getting older and my health is on my mind, I’m also a pretty small guy and putting on weight/muscle isn’t easy for me. Trying to be consistent and work on chest/back and arms throughout the week. I’ve got a pull up bar and various weight dumbbells and apps to track push ups and pull ups. Doing well and improving each week by keeping track and monthly strength tests. Not seeing it on the scales yet, having a baby leads to increase stress and severe lack of sleep which also doesn’t help for me. Will try to post about all this in more detail in future.</p><h3>Blogging</h3><p>With a new blog comes great responsibility, more blogging! Need to up my game and start a streak of posts. Is 1 a week too much?! Probably unless they’re smaller. Maybe I’ll try 1 longform a month and a small one a week. Got a few freelance, remote, dev, dad related ideas so I’ll aim to keep up momentum.</p><h3>Minimalist</h3><p>Started listening to <a href="https://www.theminimalists.com/">The Minimalist Podcast</a> last year and picked up their <strong>Essential</strong> book which I’m currently reading. Living with less is becoming more important so I’ve already started to de-clutter and had a trip to the charity shop with unwanted stuff. Hope that brushes off to my wife and I’m trying to teach that to my toddler which is kinda going ok. I have his permission to “recycle” a few of his old toys which is certainly a start!</p><blockquote><em>Love people, use things. The opposite never works.</em></blockquote><blockquote><a href="https://www.theminimalists.com/lovepeople"><em>https://www.theminimalists.com/lovepeople</em></a></blockquote><h3>Sub Goals</h3><h4>Guitar</h4><p>Each year I put down guitar as a goal and I always reach a plateau of enthusiasm and skill. Not really touched it this year but would like to pick it back up and start playing again. Set myself a full song a month previously so may</p><h4>Gaming</h4><p>Very bottom of the pile, picked up a PS4 last year with <strong>God of War</strong> which I have yet to finish and <strong>Red Dead Redemption 2</strong> at Christmas which I’ve only fired up for an hour or so :( Time is a premium and sleep is a priority those first difficult months of having a baby. Hopefully by mid year things will have settled and my free time opens up for me to play! Also have a <strong>Switch</strong> which is an amazing bit of kit so will try to pick that up too!</p><h3>Good is Better Than Perfect</h3><p>Still lots todo! I use Trello for most of my projects and it helps me keep track of things, some of which include:</p><ul><li>Add page caching (spatie/laravel-responsecache)</li><li>Add my ginger face to the homepage header</li><li>Add favicon</li><li>Move and minify all JS (instead of per page)</li><li>Setup outgoing email on contact form (currently using Mailtrap)</li><li>Upgrade to Laravel 5.8</li><li>Add old post warnings e.g. 6 months old, 1 year old</li><li>Transfer Medium posts</li><li>Add to Google Search Console</li><li>Integrate header images</li></ul><p><em>Originally published at </em><a href="https://www.jamesfairhurst.co.uk/blog/2019"><em>www.jamesfairhurst.co.uk</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5a7711be374" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel Dusk on CircleCI]]></title>
            <link>https://medium.com/@james_fairhurst/laravel-dusk-on-circleci-60bbe3872065?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/60bbe3872065</guid>
            <category><![CDATA[circleci]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[laravel-dusk]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Mon, 15 May 2017 12:44:31 GMT</pubDate>
            <atom:updated>2017-05-15T12:44:31.969Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TOe1BwfnxWeDnvdI0LXaxg.jpeg" /><figcaption>Dusk — <a href="https://unsplash.com/photos/_uAy1v3lXII">https://unsplash.com/photos/_uAy1v3lXII</a></figcaption></figure><p>I wanted to get dusk running on CircleCI for a recent project and while there are a few <a href="https://laravel-news.com/laravel-dusk-continuous-integration">recent</a> <a href="https://medium.com/@helovamut/testing-with-laravel-dusk-circleci-c36277210eb3">articles</a> unfortunately they didn’t work for me.</p><p>Using the <a href="https://laravel.com/docs/5.4/dusk#running-tests-on-circle-ci">official config file from the docs</a> as a starting point I was getting the following error:</p><pre>1) Tests\Browser\ExampleTest::testBasicExample<br>Facebook\WebDriver\Exception\UnknownServerException: unknown error: Chrome version must be &gt;= 55.0.2883.0</pre><p>So it looks like I need to update chrome, logged in via SSH and tried to do it manually using sudo apt-get update &amp; sudo apt-get upgrade however it was telling me it was fully upto date but the version still wasn’t the latest. Quite a bit of googling later led me to the following commands for installing the latest version:</p><pre>wget -q -O - <a href="https://dl-ssl.google.com/linux/linux_signing_key.pub">https://dl-ssl.google.com/linux/linux_signing_key.pub</a> | sudo apt-key add -</pre><pre>sudo sh -c &#39;echo &quot;deb [arch=amd64] <a href="http://dl.google.com/linux/chrome/deb">http://dl.google.com/linux/chrome/deb</a> stable main&quot; &gt;&gt; /etc/apt/sources.list.d/google.list&#39;</pre><pre>sudo apt-get update</pre><pre>sudo apt-get --only-upgrade install google-chrome-stable</pre><p>That did the trick and running google-chrome — version gave me an updated version and the basic dusk test was passing!</p><p>Full circle &amp; .env files are below which includes MySQL:</p><p><strong>circle.yml</strong></p><pre>machine:<br>  php:<br>    version: 7.1.3<br>  services:<br>    - mysql</pre><pre>test:<br>  pre:<br>    - wget -q -O - <a href="https://dl-ssl.google.com/linux/linux_signing_key.pub">https://dl-ssl.google.com/linux/linux_signing_key.pub</a> | sudo apt-key add -<br>    - sudo sh -c &#39;echo &quot;deb [arch=amd64] <a href="http://dl.google.com/linux/chrome/deb">http://dl.google.com/linux/chrome/deb</a> stable main&quot; &gt;&gt; /etc/apt/sources.list.d/google.list&#39;<br>    - sudo apt-get update<br>    - sudo apt-get --only-upgrade install google-chrome-stable<br>    - &quot;./vendor/laravel/dusk/bin/chromedriver-linux&quot;:<br>        background: true<br>    - cp .env.circle .env<br>    - &quot;php artisan serve&quot;:<br>        background: true</pre><pre>override:<br>    - php artisan dusk<br>    - vendor/bin/phpunit</pre><p><strong>.env.circle</strong></p><pre>APP_ENV=testing<br>APP_KEY=GENERATE_YOUR_OWN_KEY<br>APP_DEBUG=true<br>APP_LOG_LEVEL=debug<br>APP_URL=<a href="http://localhost:8000/">http://localhost:8000</a></pre><pre>DB_CONNECTION=mysql<br>DB_HOST=127.0.0.1<br>DB_PORT=3306<br>DB_DATABASE=circle_test<br>DB_USERNAME=ubuntu<br>DB_PASSWORD=</pre><pre>BROADCAST_DRIVER=log<br>CACHE_DRIVER=file<br>SESSION_DRIVER=file<br>QUEUE_DRIVER=sync</pre><pre>MAIL_DRIVER=log</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*0XIOUoQFmoifFHvYYl5zGw.png" /><figcaption>Dusk tests passing on CircleCI</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60bbe3872065" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Multiple Laravel Log Files]]></title>
            <link>https://medium.com/@james_fairhurst/configuring-multiple-laravel-log-files-a1ad1895e0e4?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1ad1895e0e4</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Thu, 19 Jan 2017 21:39:49 GMT</pubDate>
            <atom:updated>2017-01-19T21:39:49.025Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I wanted to split out log files depending on the severity level however it was a bit trickier than I expected. The <a href="https://laravel.com/docs/5.3/errors#custom-monolog-configuration">official docs</a> mention configuring Monolog but don’t provide much detail. I’ve not used the package before and hunting around the docs and Google didn’t give me much to go on and confused me.</p><p>I initially just wanted to log info levels to a separate file, thinking it would be as simple as pushing a handler with <strong>just</strong> the INFO constant that unfortunately didn’t work. Things bubble up so info &amp; above were being caught — adding in the false 3rd param didn’t have any affect.</p><p>So below you can see I’ve added <strong>DEBUG</strong> to info.log and <strong>NOTICE</strong> to laravel.log. DEBUG &amp; INFO get caught by the 1st and go to info.log and the rest get caught by the 2nd and go to laravel.log.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ac06076e536fcc72234ea7a9890ab5b/href">https://medium.com/media/7ac06076e536fcc72234ea7a9890ab5b/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1ad1895e0e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bitbucket Pipelines and Laravel]]></title>
            <link>https://medium.com/@james_fairhurst/bitbucket-pipelines-and-laravel-a51c613e2699?source=rss-b5a7cf9a0909------2</link>
            <guid isPermaLink="false">https://medium.com/p/a51c613e2699</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[James Fairhurst]]></dc:creator>
            <pubDate>Tue, 18 Oct 2016 13:34:24 GMT</pubDate>
            <atom:updated>2017-05-15T20:00:35.300Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tlggi1Uh2uokMhgQ3MpDJg.jpeg" /><figcaption>Pipelines — <a href="https://unsplash.com/photos/xNdPWGJ6UCQ">https://unsplash.com/photos/xNdPWGJ6UCQ</a></figcaption></figure><p>I recently got notified of <a href="https://bitbucket.org/product/features/pipelines">Pipelines</a> in Bitbucket which is a nice feature, I’ve used similar tools such as <a href="https://travis-ci.org/">Travis CI</a> &amp; <a href="https://codeship.com/">Codeship</a> previously which are great but having CI built into your private Bitbucket repos is super handy. Turns out it’s relatively straight forward to get up &amp; running. I wanted to quickly get a brand new 5.3 Laravel app connected so this is what I did.</p><p><strong>Don’t want to dilly-dally around here?</strong> Go straight to the <a href="https://bitbucket.org/james_fairhurst/laravel-bitbucket-pipeline">Bitbucket repo here</a>. (15/05/17 — updated to 5.4)</p><h3>Getting Setup</h3><p>Head over to the <strong>Pipelines</strong> nav section and enable Pipelines, choose <strong>PHP</strong> and click <strong>Next</strong>. Bitbucket will then open the file for editing so that you can add custom Laravel commands. First I wanted the bare minimum to run so I added a command to copy the example .env file &amp; generate a key (these can be found in the <strong>composer.json</strong> file <em>scripts</em> section):</p><pre># This is a sample build configuration for PHP.<br># Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.<br># Only use spaces to indent your .yml configuration.<br># -----<br># You can specify a custom docker image from Docker Hub as your build environment.<br>image: phpunit/phpunit:5.0.3<br><br>pipelines:<br>  default:<br>    - step:<br>        script: # Modify the commands below to build your repository.<br>          - php -r &quot;file_exists(&#39;.env&#39;) || copy(&#39;.env.example&#39;, &#39;.env&#39;);&quot;<br>          - composer install<br>          - php artisan key:generate<br>          - phpunit</pre><p>Once the tests passed I wanted to add database testing for Sqlite. I added the <strong>DatabaseMigrations</strong> trait to the <strong>ExampleTest</strong> file and created a new simple test to see a user’s email in the <strong>users</strong> table after creating it with a factory:</p><pre>&lt;?php</pre><pre>use Illuminate\Foundation\Testing\WithoutMiddleware;<br>use Illuminate\Foundation\Testing\DatabaseMigrations;<br>use Illuminate\Foundation\Testing\DatabaseTransactions;</pre><pre>class ExampleTest extends TestCase<br>{<br>    use DatabaseMigrations;</pre><pre>    /**<br>     * A basic database test example.<br>     *<br>     * <a href="http://twitter.com/return">@return</a> void<br>     */<br>    public function testDatabase()<br>    {<br>        $user = factory(App\User::class)-&gt;create();</pre><pre>        $this-&gt;seeInDatabase(&#39;users&#39;, [<br>            &#39;email&#39; =&gt; $user-&gt;email<br>        ]);<br>    }<br>}</pre><p>Next in order to use Sqlite I added env variables to the <strong>phpunit.xml</strong> file:</p><pre>&lt;php&gt;<br>    &lt;env name=&quot;APP_ENV&quot; value=&quot;testing&quot;/&gt;<br>    &lt;env name=&quot;CACHE_DRIVER&quot; value=&quot;array&quot;/&gt;<br>    &lt;env name=&quot;SESSION_DRIVER&quot; value=&quot;array&quot;/&gt;<br>    &lt;env name=&quot;QUEUE_DRIVER&quot; value=&quot;sync&quot;/&gt;<br><strong>    &lt;env name=&quot;DB_CONNECTION&quot; value=&quot;sqlite&quot;/&gt;<br>    &lt;env name=&quot;DB_DATABASE&quot; value=&quot;:memory:&quot;/&gt;</strong><br>&lt;/php&gt;</pre><p>I originally had the <strong>DB_DATABASE</strong> set to <strong>database/database.sqlite</strong> and had to create the file with a command in <strong>bitbucket-pipelines.yml</strong> however I can just use <strong>:memory:</strong> to use an in-memory db which simplifies things and speeds up the tests.</p><h3>Huzzah Passing Tests!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4BHV7kewPS-u6qxa-00j0Q.png" /><figcaption>Passing tests!</figcaption></figure><p>The link to my repo with all this is below, any issues or feedback just create an issue on the tracker:</p><p><a href="https://bitbucket.org/james_fairhurst/laravel-bitbucket-pipeline">james_fairhurst / laravel-bitbucket-pipeline</a></p><p>Lots of other things that are possible so checkout the <a href="https://confluence.atlassian.com/bitbucket/bitbucket-pipelines-792496469.html">docs</a> such as <a href="https://confluence.atlassian.com/bitbucket/notifications-for-bitbucket-pipelines-857053284.html">Slack integration</a> on build status.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a51c613e2699" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>