<?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[Spartner - Medium]]></title>
        <description><![CDATA[Creating partnerships with strategic impact through the development of market leading custom built software. - Medium]]></description>
        <link>https://medium.com/spartner?source=rss----52af03c2915c---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Spartner - Medium</title>
            <link>https://medium.com/spartner?source=rss----52af03c2915c---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 20:15:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/spartner" 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 Excel News — December ‘21]]></title>
            <link>https://medium.com/spartner/laravel-excel-news-december-21-d50b1df50278?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/d50b1df50278</guid>
            <category><![CDATA[laravel-excel]]></category>
            <dc:creator><![CDATA[Patrick Brouwers]]></dc:creator>
            <pubDate>Mon, 27 Dec 2021 11:02:49 GMT</pubDate>
            <atom:updated>2021-12-27T11:02:48.024Z</atom:updated>
            <content:encoded><![CDATA[<h3>Laravel Excel News — December ‘21</h3><p>With the end of the year in sight, the 8th Year of Laravel Excel Development comes to an end. We are looking forward to all the great things that 2022 will bring. Here’s one last update for 2021.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GsVXPr7x_axlC8S-zLs7jg.png" /></figure><h3>PHP 8.1 compatibility</h3><p>PHP celebrated its 8.1 release recently. That meant some changes would have to be done to make Laravel Excel compatible.</p><p>Laravel Excel has a Row object which has some handy methods like $row-&gt;toArray(). But you can also use the row as an array: $row[&#39;name&#39;]. The latter is achieved by using the ArrayAccessinterface.</p><h4>New typehints</h4><p>PHP 8.1 has added new typehints to the ArrayAccess interface.</p><pre>public offsetGet(mixed $offset): mixed</pre><p>Especially the mixed return type is a tricky one when supporting multiple PHP versions. The mixed return type was only added in PHP 8.0. Adding the return type would throw an error in PHP 7.x and not adding it would throw an error in PHP 8.1.</p><p>Laravel Excel currently supports PHP 7.2 till PHP 8, so we couldn’t update the return type without having to deprecate all PHP 7 versions. We currently don’t have plans to do that yet, this is scheduled for the next major release.</p><h4>The solution</h4><p>PHP 8.1 also introduced a new #[\ReturnTypeWillChange] attribute. This attribute signals PHP that a mismatching return type should not trigger the deprecation notice and can be added a method.</p><pre>#[\ReturnTypeWillChange]<br>public function offsetGet(mixed $offset) {<br>   //<br>}</pre><p>The error will now be suppressed in PHP 8.1. However in PHP 9.0 it will trigger an error. The next major release of Laravel Excel (4.0) will stop supporting PHP 7.</p><h4>Adding PHP 8.1 to our Continuous Integration</h4><p>Laravel Excel has an extensive test suite that runs on all supported PHP and Laravel versions. PHP 8.1 was added to this list to check if Laravel Excel is fully compatible with PHP 8.1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1zG6jFt2xY0Z9-abJs0QVQ.png" /></figure><h3>Support for column limit and SkipsEmptyRows</h3><p>The SkipsEmptyRows concern now uses the provided column limit when checking if the row is empty.</p><pre>class Import implements ToArray, WithColumnLimit, SkipsEmptyRows<br>{<br>    public function endColumn(): string<br>    {<br>        return &#39;D&#39;;<br>    }<br>}</pre><h3>Format column now supports ranges</h3><p>The column formatting concern now also accepts ranges as column coordinates, before it was only possible format the entire column. Now you can apply the formatting to multiple columns or just specific cells.</p><pre>class Export implements WithColumnFormatting<br>{<br>    public function columnFormats(): array<br>    {<br>        return [<br>            &#39;A&#39;     =&gt; NumberFormat::FORMAT_DATE_DDMMYYYY,<br>            &#39;B1:C4&#39; =&gt; NumberFormat::FORMAT_CURRENCY_EUR,<br>        ];<br>    }<br>}</pre><h3>Other fixes</h3><ul><li>Change default local_path configuration</li><li>Fix queueImport function to be able to assert chained jobs</li><li>Skipped failure no longer persists in ToCollection and ToArray.</li><li>Fix missing InteractsWithQueue trait in AppendToSheet jobs</li></ul><p><em>Maatwebsite is now Spartner. New name, same dedication to the open source community. Read more at </em><a href="https://spartner.software/maatwebsite-is-now-spartner"><em>https://spartner.software/maatwebsite-is-now-spartner</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKlXGkshyIIL_FEiTTsJtw.png" /></figure><p>Do you need help with integrating Laravel Excel or do you need help building a Laravel application? We are there to help you on a commercial basis. Contact us via <a href="/service/mailto:info@maatwebsite.nl">info@spartner.nl </a>or via phone +31 (0)10 744 9312 to discuss the possibilities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d50b1df50278" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/laravel-excel-news-december-21-d50b1df50278">Laravel Excel News — December ‘21</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Meet the new visual editor in JuriBlox]]></title>
            <link>https://medium.com/spartner/meet-the-new-visual-editor-in-juriblox-11e599315f84?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/11e599315f84</guid>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Patrick Brouwers]]></dc:creator>
            <pubDate>Mon, 20 Dec 2021 15:36:34 GMT</pubDate>
            <atom:updated>2021-12-20T15:36:34.442Z</atom:updated>
            <content:encoded><![CDATA[<p>Since the initial launch in 2015 Spartner has worked with our client JuriBlox to develop countless features for their legal platform. One of the key functions of the platform is the ability to create dynamic templates, which can be used to generate documents by letting the user fill out a questionnaire.</p><h3>What is JuriBlox?</h3><p>JuriBlox is a complete contract lifecycle management platform that automates the legal process and generates high quality legal documents.</p><p>Read more about our collaboration with JuriBlox on <a href="https://spartner.software/our-work/legal-automation-platform">spartner.software</a>.</p><h3>Meet the new visual mode</h3><p>The dynamic template language is built using the Twig templating engine. Since the 21.12 release, it is now possible to use a visual layer which makes it a lot easier for non-technical users to understand the dynamic nature of a document. The template and questions are now within the same mental model for the user, without having to do a translation between the template, variable and question — creating a true “What You See Is What You Get” experience.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCZHcjvd0jnFHGa3VdKQ1A.png" /><figcaption>Before (code mode) vs After (visual mode)</figcaption></figure><h3>Conditional fields</h3><p>Most of the document generation logic is handled using condition fields (like yes/no questions). Based on the answer of a that question, a part of text can be shown or hidden. The visual mode also introduces an easy way to visualize these conditionals.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FlFiE-XMBWqCcDEOG9DrnQ.png" /></figure><h3>Interested in legal tech?</h3><p>JuriBlox offers a wide range of legal tech solutions. Read more about their solutions at <a href="https://juriblox.com/">https://juriblox.com/</a></p><blockquote>Maatwebsite is now Spartner. New name, same dedication to develop your innovative custom built software. Read more at <a href="https://spartner.software/maatwebsite-is-now-spartner">https://spartner.software/maatwebsite-is-now-spartner</a>.</blockquote><p>Do you need help building a Laravel application? We are there to help you on a commercial basis. Contact us via <a href="/service/mailto:info@maatwebsite.nl">info@spartner.nl </a>or via phone +31 (0)10 744 9312 to discuss the possibilities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11e599315f84" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/meet-the-new-visual-editor-in-juriblox-11e599315f84">Meet the new visual editor in JuriBlox</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Our 3 favorite additions to TailwindCSS 3.0]]></title>
            <link>https://medium.com/spartner/our-3-favorite-additions-to-tailwindcss-3-0-dfa13d84d0d2?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/dfa13d84d0d2</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[tailwind-css]]></category>
            <dc:creator><![CDATA[Patrick Brouwers]]></dc:creator>
            <pubDate>Tue, 14 Dec 2021 14:11:25 GMT</pubDate>
            <atom:updated>2022-02-03T16:13:14.940Z</atom:updated>
            <content:encoded><![CDATA[<h3>Our 3 favorite additions to Tailwind CSS 3.0</h3><p>At Spartner we have used Tailwind CSS since the very first alpha release. Last week they released a new major version: 3.0.0. We’ll explain our favorite new features and why we are looking forward to using them!</p><h3>JIT mode as default</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EMVrmjjTw6FKqP0g0_YXIA.png" /><figcaption>Screen grab from the official announcement video <a href="https://www.youtube.com/watch?v=TmWIrBPE6Bc">https://www.youtube.com/watch?v=TmWIrBPE6Bc</a></figcaption></figure><p>One of the big new things in 3.0 is the stable release of the JIT (just-in-time) mode which was in beta during the 2.0 version.</p><p>The JIT mode comes with a lot of advantages:</p><ul><li><strong>Extremely fast build times. </strong>On some of our bigger projects at Spartner the building time could take up to 45s, however with the JIT mode enabled this goes down to &lt;1s.</li><li><strong>Generating arbitrary styles without custom CSS</strong>. This is very useful for the situation you need a very specific value (like a sidebar width or an absolute element position).</li><li><strong>All variants are enabled</strong>. No more enabling of variants per component in the config file. Variants like :hover can now be used out of the box on every utility.</li><li><strong>Smaller CSS files</strong>. The JIT mode only generates the CSS classes that you need. This has two advantages: smaller files (faster loading in local development) and development en production builds are identical.</li></ul><h3>Color shadows</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H2t39TTQoG1SknLW9obhcg.png" /></figure><p>Most Tailwind utilities can be used in a composable way. For shadows this wasn’t possible yet and you would have to create a custom shadow like shadow-lg-blue. Now the shadow color can be modified by adding a utility like `shadow-blue-500/50`.</p><pre>&lt;button class=”bg-blue-500 shadow-lg shadow-blue-500/50 ...&gt;</pre><p>Tailwind achieves this by using CSS variables in the shadow utilities:</p><pre>.shadow-lg {<br> — tw-shadow-colored: 0 10px 15px -3px var( — tw-shadow-color),0 4px 6px -4px var( — tw-shadow-color);<br>}</pre><p>The color utility sets this color variable:</p><pre>.shadow-indigo-500\/50 {<br> — tw-shadow-color: rgb(99 102 241/0.5);<br>}</pre><p>The new shadow utilities will give us even more possibilities at creating great looking designs.</p><h3>Print variant</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C1YMqiovOrl4q2UAeQtwUw.png" /><figcaption>Screen grab from the official announcement video <a href="https://www.youtube.com/watch?v=TmWIrBPE6Bc">https://www.youtube.com/watch?v=TmWIrBPE6Bc</a></figcaption></figure><p>At Spartner, we develop custom CRM and ERP software and some of our clients still hold value in printing physical copies of their customer’s data.</p><p>The new print variant allows to specify styles that will only be loaded when dealing with print. In classic CSS all these styles would have to be wrapped inside a media query; Tailwind does that for you. This can be helpful for hiding specific elements when printing.</p><pre>&lt;article class=&quot;print:hidden&quot;&gt;</pre><h3>Upgrading</h3><p>Upgrading from 2.1 is very easy, especially if you are already using the JIT mode in beta. Their upgrade guide can be found here: <a href="https://tailwindcss.com/docs/upgrade-guide">https://tailwindcss.com/docs/upgrade-guide</a></p><p>We are looking forward to what a bright Tailwind CSS future holds for us!</p><blockquote>Maatwebsite is now Spartner. New name, same dedication to the open source community. Read more at <a href="https://spartner.software/maatwebsite-is-now-spartner">https://spartner.software/maatwebsite-is-now-spartner</a>.</blockquote><p>Do you need help with TailwindCSS or do you need help building a Laravel application? We are there to help you on a commercial basis. Contact us via <a href="/service/mailto:info@maatwebsite.nl">info@spartner.nl </a>or via phone +31 (0)10 744 9312 to discuss the possibilities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dfa13d84d0d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/our-3-favorite-additions-to-tailwindcss-3-0-dfa13d84d0d2">Our 3 favorite additions to TailwindCSS 3.0</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[New milestone: 20 million downloads for Laravel Excel]]></title>
            <link>https://medium.com/spartner/new-milestone-20-million-downloads-for-laravel-excel-55f31ab562b4?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/55f31ab562b4</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[laravel-excel]]></category>
            <category><![CDATA[laravel-5]]></category>
            <dc:creator><![CDATA[Patrick Brouwers]]></dc:creator>
            <pubDate>Wed, 22 Jul 2020 15:30:41 GMT</pubDate>
            <atom:updated>2020-07-24T09:12:04.574Z</atom:updated>
            <content:encoded><![CDATA[<p>Not too long ago we celebrated the 10th million download of Laravel Excel and today it’s time to celebrate a new milestone! Laravel Excel has reached 20 million downloads!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pzF0jO-9zl_qDo2CrmbpbQ.png" /></figure><p>We are happy to have reached this milestone and thank you all for using our package over the last 6,5 years! Cheers to many more imports and exports!</p><h3>Laravel Excel 3.1.20</h3><p>In other news, we have released Laravel Excel 3.1.20 with some improvements for running imports on Vapor and working with row numbers, along with some fixes and changes. You can find a write up about this new release here.</p><h3>New features</h3><h4>Re-sycing remote temporary file</h4><p>When dealing with a multi server setup (and thus using a remote temporary file), it’s possible for the clean up that occurs after entire queue has been run to only cleanup the server that the last AfterImportJob runs on. The rest of the server would still have the local temporary file stored on it. In this case your local storage limits can be exceeded and future imports won’t be processed (This is especially an issue with Vapor).</p><p>To mitigate this you can set the new config settings (force_resync_remote) to true. After every queued chunk the local temporary file will be deleted on the server that processed it. Without this setting it will only happen at the end of the process.</p><h4>Remember row number</h4><p>A new trait was added that helps keeping track of the current row number. This can be especially useful when dealing with the ToModel concern. You can get the current row number by using the `$this-&gt;rowNumber` property.</p><pre>new UsersExport implements ToModel<br>{<br>    use RemembersRowNumber;</pre><pre>    public function model(array $row)<br>    {<br>       // You can use the current row number.<br>       $this-&gt;rowNumber;<br>    }<br>}</pre><h4>Remember chunk offset</h4><p>In additional to the row number trait also a chunk offset trait was added. It keeps track of the start row of the current chunk. This can be especially helpful when dealing with Chunked Imports.</p><pre>new UsersExport implements ToModel, WithChunkReading<br>{<br>     use RemembersChunkOffset;</pre><pre>     public function model(array $row)<br>     {<br>         // You can get the current chunk offset<br>         $this-&gt;getChunkOffset();<br>      }<br> <br>      public function chunkSize(): int<br>      {<br>         return 50;<br>      }<br>}</pre><h4>WithColumnLimit concern</h4><p>Another addition is the WithColumnFilter concern, it allows to specify an end column. This can be useful if you only want to read a very specific range of columns.</p><pre>new UsersImport implements ToModel, WithColumnLimit<br>{</pre><pre>      public function model(array $row)<br>      {<br>          // $row will only contain 2 columns (A &amp; B)       <br>      }<br> <br>      public function endColumn(): string<br>      {<br>         return &#39;B&#39;;<br>      }<br>}</pre><h4>WithReadFilter concern</h4><p>Behind the scenes read filters are used for chunk reading and the row limit concern. In some cases you might want to filter or skip rows yourself. You can do now by implementing the WithReadFilter concern.</p><pre><em>class CustomFilter implements </em>IReadFilter<br>{<br>    <em>public function </em>readCell($column, $row, $worksheetName = &#39;&#39;)<br>    {<br>       <em>return </em>$row &lt; 10;<br>    }<br>}</pre><p>In your export:</p><pre>new UsersExport implements WithReadFilter<br>{<br>    <em>public function </em>readFilter(): IReadFilter<br>    {<br>        return new CustomFilter();<br>    }<br>}</pre><h4>Publishing the stubs</h4><p>It’s now possible to publish the stubs that are used when using the php artisan make:import and php artisan make:export commands so you can change them to your liking.</p><p>php artisan stub:publish (Laravel 7.x)</p><h3>Changes</h3><h4>Interacting with queued jobs</h4><p>The InteractsWithQueue trait was added to the ReadChunk job. The trait allows for the job to be released back onto the queue, useful for instance if using it with the funnel or throttle methods on the Redis facade.</p><h4>Retry until and middleware on queued imports</h4><p>It’s possible to specify a retry until method and add middleware to the import:</p><pre>class UsersExport implements ShouldQueue<br>{<br>    public function retryUntil()<br>    {<br>        return now()-&gt;addSeconds(5);<br>    }<br> <br>    public function middleware()<br>    {<br>       return [<br>         new RateLimited,<br>       ];<br>    }<br>}</pre><p>More about job middleware can be found in the Laravel documentation: <a href="https://laravel.com/docs/7.x/queues#job-middleware">https://laravel.com/docs/7.x/queues#job-middleware</a></p><h4>Using WithValidation with FromCollection &amp; FromArray</h4><p>This release also added support for combining those concerns and works in a similar fashion as for Model imports.</p><h4>Read filters for WithLimit and HeadingRowImport</h4><p>WithLimit concern and HeadingRowImport now use read filter, which means it will now only read the necessary rows.</p><h4>Bump of minimum version PhpSpreadsheet</h4><p>The minimum version of PhpSpreadsheet was bumped to 1.14.</p><h3>Fixes</h3><p>A few things were fixed in this release:</p><ul><li>Fixed test helper docblocks on the Excel facade.</li><li>Fix for importing with a start row beyond the highest row.</li><li>Fixed `BeforeSheet` and `AfterSheet` events receiving exportable instance instead of importable when calling on an Import.</li><li>Fix for value binders not working in queued exports.</li><li>Fix when using WithLimit concern when having less rows than the limit.</li><li>Fix AfterImport job being fired twice if not using queueing.</li><li>Raw() method now also available on Exportable.</li><li>Fix for breaking changes in PhpSpreadsheet with empty enclosures.</li></ul><p>See the full changelog here: <a href="https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/CHANGELOG.md#3120---2020-07-22">https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/CHANGELOG.md#3120---2020-07-22</a></p><p>Read more about the package at: <a href="https://laravel-excel.com/">https://laravel-excel.com/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*o-BnlnmbNNV7GoRVK_deTA.jpeg" /></figure><p>Don’t forget to send us a postcard of your hometown if you use Laravel Excel. We love to receive them!</p><p><strong>Maatwebsite</strong><br>Markt 2<br>6231 LS Meerssen<br>The Netherlands</p><p>Do you need help with integrating Laravel Excel or do you need help building a Laravel application? We are there to help you on a commercial basis. Contact us via <a href="/service/mailto:info@maatwebsite.nl">info@maatwebsite.nl </a>or via phone +31 (0)10 744 9312 to discuss the possibilities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55f31ab562b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/new-milestone-20-million-downloads-for-laravel-excel-55f31ab562b4">New milestone: 20 million downloads for Laravel Excel</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Should “normal” companies adopt blockchain in 2020]]></title>
            <link>https://medium.com/spartner/should-normal-companies-adopt-blockchain-in-2020-132175b6cf20?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/132175b6cf20</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[investment]]></category>
            <category><![CDATA[business-strategy]]></category>
            <dc:creator><![CDATA[Arne Schoenmakers]]></dc:creator>
            <pubDate>Thu, 10 Oct 2019 10:22:11 GMT</pubDate>
            <atom:updated>2019-10-10T10:22:10.883Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Many of us enjoy a daily dose of blockchain innovation news. With crypto markets financially on the move again, one could start to believe that blockchain is actually going mainstream this time round. In my mind, “mainstream” suggests that we will see solid mid-sized companies starting to dip their toes into the wells of blockchain fortune. That’s why I ask:</em></p><p><strong><em>Is it time for “normal” companies to invest in blockchain technology?</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vi6zMJSPlZaP3TrDDyLvyg.jpeg" /></figure><p>In this article I will give my viewpoint on the potential value of blockchain for “normal” companies. Please note that this viewpoint does not apply to blockchain startups or Facebook-like conglomerates, which would require a totally different rational. Instead, these are regular mid-sized companies that do not want to blow their tech budget, by jumping on the latest hype train.</p><h3>Blockchain is the best way to secure company data!</h3><p>No, I don’t think it is. Blockchain isn’t the newest and most secure database. Some would claim that blockchain can be the quick fix solution to all database security issues. It seems very promising to introduce an immutable ledger, protected by an advanced encryption algorithm, into your company. However, please take a step back to think about the issues that blockchain would actually solve?</p><p>The main issue is that blockchain doesn’t solve any security problems by itself. It still requires control of private keys. Furthermore, your data servers need to be protected. In a blockchain these servers are now transformed into “nodes”, but they do still require protecting. A faulty choice in these fields can put all your data at risk.</p><h3>Benefit from the lack of trust issues</h3><p>What a blockchain will help with, is the lack of trust between parties, who do not want to go through a intensive contracting negotiations phase. This will be able to save both time and costs on lawyers or notaries. The challenge would then be, how does my day to day business practice translate into an online, trustless, algorithm? In many cases, this is pretty difficult.</p><p>Let’s take my field of business as an example; developing web-based software platforms. Even though this is a digital asset, it doesn’t easily translate into a trustless (smart) contract. The main concern would be, when delivering a service, the receiving party must verify that it was delivered appropriately. Hence, I need to trust that party to do an honest assessment.</p><p>I can off course ask a client to lock the money (crypto) up front in a smart contract, but I still require him to verify the quality of my services. From the client’s side, he needs to trust me to deliver the service according to the agreement. Hence, it’s very hard to write a smart contract that acts as a third party to verify if the service was delivered properly.</p><p>Maybe a solution can be found in building a link between Test Driven Development (TDD) and a smart contract. When all tests of the TDD are met, the smart contract is executed and payment is fulfilled. Unfortunately, as automated tests do not verify HOW the test came to succeed, I still see many problems in this approach.</p><p><em>Have you identified an trust-less approach that works for your industry?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eOQNGL86JdOvQlAK" /><figcaption>Photo by <a href="https://unsplash.com/@cgower?utm_source=medium&amp;utm_medium=referral">Christopher Gower</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Does immutability add value?</h3><p>An additional problem is, that most business software is actually not aided by actual immutability. Mid-sized companies often need to fix user input, control access, apply changes in existing workflows or manage large amounts of customer data. Furthermore, most of these steps need to be done without the client’s consent. This cannot really work if the client holds the private keys to his data.</p><p>One could of course resolve this by holding all the private keys for the companies’ customers. But doesn’t this contradict your choice for blockchain in a big way?</p><h3>Is any enterprise blockchain mature enough?</h3><p>Lastly, one should ask the question if existing enterprise oriented blockchains are secure or mature enough to start working with them. Can they survive attacks? Will network updates impact the way you’re using them? For how many years will this blockchain continue to evolve? If it will become very popular, will it be able to scale?</p><figure><img alt="CryptoKitties congestion" src="https://cdn-images-1.medium.com/max/1024/0*we_5Q2rqppvsGY-X.png" /><figcaption>Requests run through Infura nodes spiked in early December as CryptoKitties took off.</figcaption></figure><p>Next to Bitcoin (BTC), which isn’t smart contract oriented, the only real mature blockchain seems to be Ethereum (ETH). However, one can certainly remember the CryptoKitties<a href="https://media.consensys.net/the-inside-story-of-the-cryptokitties-congestion-crisis-499b35d119cc"> congestion</a> issue. Therefore, I wouldn’t be able to name any blockchain that will provide assurances, apart from Bitcoin (BTC).</p><p>Even if a blockchain will solve all of the issues mentioned above, one must still ask, why blockchain? For example, if you need extensive security, wouldn’t you rather choose to encrypt; the connection, the database, it’s records and/or all files. Using the latest encryption standards, like Libsodium, might be much more practical and less time consuming.</p><h3>High value solutions for mid-sized companies</h3><p>Hence, for all the love that I want to give to blockchain innovations, I need to conclude that it is not the go-to solution for enterprise solutions, yet. Most mid-sized companies are still much better off building non-blockchain software, also in 2020.</p><p>For example, they can easily utilize the power of mature frameworks and open source software. At our company, we use a LAMP stack with Laravel, VueJS, Bootstrap or Tailwind for this. It enables us to quickly build fast and glorious features, with a high level of security and encryption options.</p><h3>Why blockchain still is fantastic!</h3><p>Don’t get me wrong. I am very enthusiastic about smart contract blockchain innovations, ranging from Ethereum, EOS, to NEO, Lisk to smaller business blockchains like Stratis and Neblio. However, all my enthusiasm is focused on initiatives that seem very disruptive, but are yet unproven. Mid-sized companies should simply wait for the real world solutions to show themselves, and adopt these services when they do.</p><p>Or, as the great Andreas M. Antonopoulos likes to put it:</p><p><em>“Check if a blockchain project needs to be borderless, open, neutral, global &amp; censorship resistant. If it’s not, you don’t need a blockchain. In fact, it’s a slow, inefficient and expensive database which would be much better tackled with a existing database technology, than blockchain.”</em></p><p>The latter might get more investors interested though. :)</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FqlAhXo-d-64%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DqlAhXo-d-64&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FqlAhXo-d-64%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f44ae184d69aa5292a88b89ab24d7388/href">https://medium.com/media/f44ae184d69aa5292a88b89ab24d7388/href</a></iframe><p><em>Written by Arne Schoenmakers, managing director at </em><a href="https://maatwebsite.com/"><em>Maatwebsite.</em></a><em>com</em>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=132175b6cf20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/should-normal-companies-adopt-blockchain-in-2020-132175b6cf20">Should “normal” companies adopt blockchain in 2020</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Science-Fiction made me a better software engineer]]></title>
            <link>https://medium.com/spartner/how-science-fiction-made-me-a-better-software-engineer-5ead2c0704f5?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/5ead2c0704f5</guid>
            <category><![CDATA[star-trek]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[science-fiction]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[influence]]></category>
            <dc:creator><![CDATA[Frank Peters]]></dc:creator>
            <pubDate>Wed, 21 Aug 2019 08:31:01 GMT</pubDate>
            <atom:updated>2019-08-21T08:31:01.306Z</atom:updated>
            <content:encoded><![CDATA[<p>The most important aspect of a software development team is the fact that we are all individuals with each our backgrounds, interests and specialities. This is this first in a series where we like to show the faces of our team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*03yY-30ktambfODi1fmOlg.jpeg" /></figure><p>Hi, I’m Frank and I started working for Maatwebsite in 2009. The reason I went into IT is very simple; I’ve always been a science-fiction fan and have been fascinated by the possibilities of future technologies. From a very young age I’ve been fiddling around more with software than hardware so to start a career in software was a logical path for me.</p><p>In my teenage years I discovered Star Trek and that had a big impact on my life. For the people that wonder about Star Trek; it is a story about the promise of humanity and what great things we can accomplish if we have the right intentions. Humanity created, with help of technology, a society without poverty, famine or disease; a utopia if you will (a shrill contrast with a lot of the dystopian scifi out there at the time).</p><p>Technology plays a major part in Star Trek. While I liked the idea of space exploration; I was more interested in the little things. The interesting UI they have to work with, voice controlled computers, replicated food (basically 3D printed), small communication devices, instantaneous translation. Sound familiar? It’s technology that we have today but it was imagined over 50 years ago!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmtEr7bSXuWWNXQ8oakf2Q.jpeg" /><figcaption>LCARS computer interface. Picture taken by Frank Peters at Movie Park Germany.</figcaption></figure><p>Due to budget constraints the LCARS user interface did not show its full potential. The idea was that it adapts to the user’s needs. Parts of the interface would change to relevant controls for the task at hand.</p><p>During my studies, Communication and Multimedia Design, we also had a philosophical course on technology. Because of my passion for science fiction I wrote an essay explaining how I see the technology of Star Trek mirrored with the present day. I now realise how to the point that essay would have been in 2019; I wrote about the dangers of applying software and technology in the wrong ways and having control over the population rather than technology being an enrichment for our lives to make it trouble free so that we can focus on bettering ourselves as human beings.</p><p>In Star Trek we see that life is about exploration. Obviously the TV show focuses on <em>space</em> exploration. But some episodes gave us hints about life on Earth. As the society changed to a state where we do not have money anymore, thanks to technology for the most part, people did not have to spend 8 hours a day locked up in an office. No; they were free to explore other depts of us as a human being. Like becoming an historian or artist.</p><p>Having access to everything they need eliminated wars and conflicts (on Earth at least). This also resonated on a personal level; there were no social divides anymore. No need to keep up appearances. Mirror that with today’s society where we are constantly working on our ‘social profiles’, or competing with your colleagues to who gets the promotion you so need.</p><p>Star Trek showed technology that was unobtrusive and easy to use. It was always there, available to help you. I apply these principles to this day in my work. The software that I write needs to be of added value to our clients and it needs to help them achieve their goals. This not only applies to functionality but also to usability. The LCARS interface shown in the photo above resembles a modern Android user interface; a bright colour palette on a dark background with flat buttons and subtle gradients. Now take a look at the screenshot below. The bright colours really help a user pick the actions that are most important.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ypZjYR4MxM8wo86mthowFA.png" /><figcaption>Sneak peak of the new landlord portal of Maastrichthousing</figcaption></figure><p>So while my love for science fiction inspires my work it also makes work fun as I share this interest with my other colleagues and we can discuss new movies, books and tv-shows at length bringing us closer together as human beings. And that makes it come full circle.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ead2c0704f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/how-science-fiction-made-me-a-better-software-engineer-5ead2c0704f5">How Science-Fiction made me a better software engineer</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MySQL 8 Polygonal map search]]></title>
            <link>https://medium.com/spartner/mysql-8-polygonal-map-search-f3caeb614ffd?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/f3caeb614ffd</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[geolocation]]></category>
            <dc:creator><![CDATA[Jochem Fuchs]]></dc:creator>
            <pubDate>Wed, 14 Aug 2019 13:58:33 GMT</pubDate>
            <atom:updated>2019-08-14T14:18:33.123Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2v1F-Q7wVnj8Lrm-MGnpMA.jpeg" /></figure><p><em>A tutorial for building easy locator maps</em></p><h3>Welcome back!</h3><p>Last week I published an article about the powerful combo <a href="https://medium.com/p/mysql-8-and-maps-a-power-combo-cb33f62168ef">MySQL 8 and Maps</a> can be. Like I promised at the end of that article, this week I published a tutorial on how to implement a simple example of this technique.</p><p>In this quick tutorial I will guide you through building a very simple locator map. Maps like these are common for finding stores, properties, AirBNB homes or even Geocaches. This map won’t be as fully featured as those examples of course, but it will implement the base features in a much simpler way than we commonly see.</p><p>I’m making a few assumptions about the knowledge of you as reader, and if you don’t think you fit that image, you may need to research these techniques first:</p><ul><li>You are able to create a new Laravel +Vue application from scratch.</li><li>You understand Docker enough to run it, or are able to set up your own environment to run this application.</li><li>You have a decent understanding of MySQL.</li><li>You are able to create and run a database migration through Laravel.</li><li>You’ve worked with the Google Maps JavaScript API before or have a basic understanding of it.</li><li>You have some idea what I mean by geolocation and what a coordinate is.</li><li>(optional) You’ve read my article about <a href="https://medium.com/maatwebsite/the-best-way-to-locate-in-mysql-8-e47a59892443">MySQL 8 and Geolocation</a></li></ul><p>Also because this is just a technical demo, I will dispense some best practises like TDD, or tests in general. And in some places the code is not the way how I would usually write it, because additional abstraction would just be a distraction here.</p><blockquote><em>This is not meant to be copy-pasted into a real world project without some significant changes!</em></blockquote><p>So without further ado, let’s get started!</p><h3>Step 1: What do we need?</h3><p>For the purposes of this demo, we’ll be making a Laravel + Vue application. From here on out I will assume that you have at least a moderate level of understanding of these tools.<br>Also, I work with Docker and the demo application I will provide at the end does come with a Docker setup, but you can ignore all that if you prefer to run the application in any other way.</p><p><strong>Tools required:</strong></p><ul><li>Laravel 5.8</li><li>Docker (Unless you set up your own environment)</li><li>VueJS 2</li><li>Google Maps JavaScript API</li></ul><h3>Step 2: Database</h3><p>For this application we really only need one table. Let’s call it markers and set up a migration for it.</p><pre>$ php artisan make:migration create_markers</pre><p>The migration itself is very small. Just a primary key and a coordinate column.</p><pre>Schema::<strong>create</strong>(&#39;markers&#39;, function (Blueprint $table) {<br>    $srid = env(&#39;SPATIAL_REF_ID&#39;, 4326);<br><br>    $table-&gt;bigIncrements(&#39;id&#39;);</pre><pre>    $table-&gt;point(&#39;coordinate&#39;, $srid);</pre><pre>    $table-&gt;string(&#39;lat&#39;)-&gt;<strong>virtualAs</strong>(&#39;ST_X(coordinate)&#39;);<br>    $table-&gt;string(&#39;lon&#39;)-&gt;<strong>virtualAs</strong>(&#39;ST_Y(coordinate)&#39;);<br><br>    $table-&gt;timestamps();<br>});</pre><p>As a coordinate always consists of two values (latitude and longitude), we need a point column. This type of column is a spatial field with an x and y value. Attentive readers may have noticed the first line:</p><pre>$srid = env(‘SPATIAL_REF_ID’, 4326);</pre><p>If you’ve read my other article you will recognise the term SRID but if you haven’t let me explain it briefly.</p><blockquote>A <strong>spatial reference system</strong> (<strong>SRS</strong>) or <strong>coordinate reference system</strong> (<strong>CRS</strong>) is a <a href="https://en.wikipedia.org/wiki/Coordinate_system">coordinate-based</a> local, regional or global system used to locate geographical entities.</blockquote><p>MySQL 8 allows you to define the ‘Spatial Reference ID’ per column. In use cases like store locators, you will almost always want to use <a href="https://en.wikipedia.org/wiki/World_Geodetic_System">WGS 84</a>, which is identified by 4326. By using the correct reference system you will ensure that a coordinate in your database matches the same location as intended when projecting it on a map.</p><p>Looking at the actual column setup, you’ll also see I have added two virtual columns. Because the actual coordinate column contains binary data, it is hard to interpret in your application. So for ease of use, we add these virtual columns to directly access the latitude and longitude values.</p><pre>$table-&gt;point(&#39;coordinate&#39;, $srid);</pre><pre>$table-&gt;string(&#39;lat&#39;)-&gt;<strong>virtualAs</strong>(&#39;ST_X(coordinate)&#39;);<br>$table-&gt;string(&#39;lon&#39;)-&gt;<strong>virtualAs</strong>(&#39;ST_Y(coordinate)&#39;);</pre><p>And that’s really all we need to set up the database.</p><h3>Step 3: Data structure &amp; handling</h3><p>The coordinate is the most important data object in this demo application, and we want to ensure we can rely on it being correct. So let’s start by creating a simple DTO:</p><pre>namespace App;<br><br>use Illuminate\Contracts\Support\Arrayable;<br><br>class Coordinate implements Arrayable<br>{<br>    <em>/**<br>     * </em><strong><em>@var </em></strong><em>float<br>     */<br>    </em>private $lat;<br><br>    <em>/**<br>     * </em><strong><em>@var </em></strong><em>float<br>     */<br>    </em>private $lon;<br><br>    <em>/**<br>     * </em><strong><em>@param </em></strong><em>float $lat<br>     * </em><strong><em>@param </em></strong><em>float $lon<br>     */<br>    </em>public function __construct(float $lat, float $lon)<br>    {<br>        $this-&gt;lat = $lat;<br>        $this-&gt;lon = $lon;<br>    }<br><br>    <em>/**<br>     * </em><strong><em>@return </em></strong><em>float<br>     */<br>    </em>public function getLat(): float<br>    {<br>        return $this-&gt;lat;<br>    }<br><br>    <em>/**<br>     * </em><strong><em>@return </em></strong><em>float<br>     */<br>    </em>public function getLon(): float<br>    {<br>        return $this-&gt;lon;<br>    }<br><br>    <em>/**<br>     * Get the instance as an array.<br>     *<br>     * </em><strong><em>@return </em></strong><em>array<br>     */<br>    </em>public function toArray()<br>    {<br>        return [<br>            &#39;lat&#39; =&gt; $this-&gt;getLat(),<br>            &#39;lon&#39; =&gt; $this-&gt;getLon(),<br>        ];<br>    }<br>}</pre><p>You will notice I always use floats for the two coordinate parts. This may seem obvious, but I’ve seen far too many examples of using strings (and consequently varchars in the database) to not point this out.</p><h4>Markers Model</h4><p>Next we’ll create a model for our markers table.</p><pre>$ php artisan make:model Marker</pre><p>We’ll use the Coordinate DTO for setting and getting the coordinate from the model.</p><pre>namespace App;<br><br>use Illuminate\Support\Facades\DB;<br>use Illuminate\Database\Eloquent\Model;<br><br>class Marker extends Model<br>{<br>    <em>/**<br>     * </em><strong><em>@var </em></strong><em>array<br>     */<br>    </em>protected $fillable = [<br>        &#39;coordinate&#39;,<br>    ];<br><br>    <em>/**<br>     * </em><strong><em>@param </em></strong><em>Coordinates $coordinates<br>     *<br>     * </em><strong><em>@return </em></strong><em>$this<br>     */<br>    </em>public function setCoordinate(Coordinate $coordinates): self<br>    {<br>        $srid = env(&#39;SPATIAL_REF_ID&#39;, 4326);<br>        $lat  = $coordinates-&gt;getLat();<br>        $lon  = $coordinates-&gt;getLon();<br><br>        $this-&gt;attributes[&#39;coordinate&#39;] = DB::<strong>raw</strong>(&quot;ST_GeomFromText(&#39;POINT($lat $lon)&#39;, $srid)&quot;);<br><br>        return $this;<br>    }<br><br>    <em>/**<br>     * </em><strong><em>@return </em></strong><em>Coordinate<br>     */<br>    </em>public function getCoordinate(): Coordinate<br>    {<br>        return new Coordinate($this-&gt;lat, $this-&gt;lon);<br>    }<br>}</pre><p>For this demo app, we’ll not create a repository or factory or similar, but of course some of this logic may be written very differently or in different places in a real life application.</p><p>Take note of the use of ST_GeomFromText in the setter. This is required to be able to set your coordinate. Because Laravel and Eloquent are awesome, it’s quite easy to hook into the saving model event and do this logic there. <br>If you have multiple models that use coordinates, you may even want to create an abstract class, trait, factory or some other higher order class for.</p><p>For now we will stick to a simple implementation.</p><h4>Creating a marker</h4><p>With the above two classes we can create our first marker:</p><pre>$coordinate = new Coordinate(50.8815228, 5.7469309);</pre><pre>$marker     = (new Marker)<br>                -&gt;setCoordinate($coordinate)<br>                -&gt;save();</pre><p>In the demo code I have shared on Github I have also added a name field and a setter for that field. But it’s optional.</p><h3>Step 3b: Creating a random list of coordinates</h3><p>A demo isn’t much of a one without some actual data to test it with. So we’re taking a small sidetrack here to create a random marker generator.</p><p>Why a generator and not a seeder? Because I want you to be able to create a list of markers that’s actual in an area around you, and not just around the Maatwebsite office. And because it’s fun!</p><p>To start, let’s generate a console command</p><pre>$ php artisan make:command GenerateRandomLocations</pre><p>The command itself will use the two previous classes we created, and we will make use of Faker to fill in some random data.</p><p>Let’s take a look at the signature first, to show what the command can do:</p><pre><em>/**<br> * The name and signature of the console command.<br> *<br> * </em><strong><em>@var </em></strong><em>string<br> */<br></em>protected $signature = &#39;make:locations <br>                            {startLat=50.884408: Starting latitude} <br>                            {startLon=5.756073: Starting longitude} <br>                            {radius=50: Limiting radius from starting point in Km} <br>                            {amount=100: Amount of locations to generate}&#39;;</pre><p>We’re using the familiar make prefix. Then there are a few arguments to provide:</p><ul><li>startLat: The latitude of the coordinate that will be at the centre of the newly created list of coordinates.</li><li>startLon: The longitude of that same centre coordinate.</li><li>radius: This will determine the maximum distance of the generated coordinates, in kilometers.</li><li>amount: The amount of locations to generate.</li></ul><p>By default, without arguments, the command will generate 100 points in a 5km radius from the Maatwebsite office.</p><p>The “magic” happens in the handle method:</p><pre><em>/**<br> * </em><strong><em>@param </em></strong><em>GeoCalculationService $service<br> */<br></em>public function handle(GeoCalculationService $service)<br>{<br>    $faker         = Factory::<em>create</em>();<br>    $startingPoint = $this-&gt;getStartingPoint();<br><br>    for($i = 0; $i &lt;= $this-&gt;getAmount(); $i++) {<br>        $newCoordinate = $service-&gt;randomCoordinate($startingPoint, $this-&gt;getRadius());<br><br>        (new Marker)<br>            -&gt;setName($faker-&gt;<strong>name</strong>)<br>            -&gt;setCoordinate($newCoordinate)<br>            -&gt;save();<br>    }<br>}</pre><p>We are using the Faker factory for generating names (remember I said they were optional before? If you don’t want names, just forget about this part).</p><p>Within a for loop (based on the chosen amount value) we will then use a service class to generate a random coordinate based on the provided arguments.</p><h4>The service class</h4><p>The complete service class will be provided within the demo app on Github. But for the purpose of this article I’d like to point out this small part:</p><pre><em>/**<br> * </em><strong><em>@param </em></strong><em>Coordinate $coordinates<br> * </em><strong><em>@param </em></strong><em>int         $maxDistance<br> *<br> * </em><strong><em>@return </em></strong><em>Coordinate<br> */<br></em>public function randomCoordinate(Coordinate $coordinates, int $maxDistance): Coordinate<br>{<br>    $heading  = mt_rand(0, 359);<br>    $distance = mt_rand(0, $maxDistance);<br><br>    return $this-&gt;project($coordinates, $distance, $heading);<br>}</pre><p>To create a random coordinate we first determine a random heading (within the 360 degrees of a compass). Then we determine a random distance within the limit provided.</p><p>The project function, which I will not explain here (as it could almost merit an article in and of itself) will use a technique (surprisingly) called <a href="https://www.geocachingtoolbox.com/index.php?lang=en&amp;page=coordinateProjection">projection</a> to calculate a coordinate on the heading and distance from the provided starting point. <br>Those of you who have dabbled with Geocaching may recognise it. It can also be done with a simple compass and walking, but for our purposes we don’t really have the time for that.</p><p>I’ve mentioned the haversine formula in my other article, and the formula to project a new coordinate is closely related to that one. It takes into account things like the radius of the earth and then does a whole lot of sin/cos/tan calculations that I barely understand myself. So I will not bother you with an explanation. The link above will allow you to test the projections we make to see if they are correct, if you’d like to make sure.</p><h3>Step 4: Find locations</h3><p>Ok, so now we are able to create random coordinates within a fixed radius, how should we go about finding the points?</p><p>We are skipping ahead a bit, because I haven’t explained how to get the input arguments we need for this, but let me first explain how we can find point within a known polygon.</p><pre><em>/**<br> * </em><strong><em>@param </em></strong><em>array $mapBounds<br> * </em><strong><em>@param </em></strong><em>array|null $markerIds<br> *<br> * </em><strong><em>@return </em></strong><em>Builder<br> */<br></em>public function findByBounds(array $mapBounds)<br>{<br>    ...<br><br>    [   &#39;south&#39; =&gt; $south,<br>        &#39;west&#39;  =&gt; $west,<br>        &#39;north&#39; =&gt; $north,<br>        &#39;east&#39;  =&gt; $east<br>    ] = $mapBounds;<br><br>   ...<br>}</pre><p>The findByBounds methods expects an array of points that represent the two edges of the rectangle. We can get this info from Google Maps, and I’ll show you how later. For now let’s assume that array will always contain the following exact data and in this exact order:</p><ul><li>The southern most longitude of the rectangle.</li><li>The western most latitude of the rectangle</li><li>The northern most longitude of the recangle</li><li>The eastern most latitude of the rectangle.</li></ul><p>Let me use this picture I’ve graciously nicked from StackOverflow to illustrate what I mean:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*JtMYBVexb1_NHmW3.png" /></figure><p>Point C represents the South-West corner of a rectangle, where B represents the North-East corner. <br>When drawing the <a href="https://en.wikipedia.org/wiki/Minimum_bounding_rectangle">minimum bounding rectangle</a> of these two points, you’d basically get this red rectangle.<br>So all we need for the full rectangle are just the two corners, and thankfully Google Maps provides these easily.</p><p>So if we take a look at the full findByBounds method, we can understand how these can fit in the query we need:</p><pre><em>/**<br> * </em><strong><em>@param </em></strong><em>array $mapBounds<br> *<br> * </em><strong><em>@return </em></strong><em>Builder<br> */<br></em>public function findByBounds(array $mapBounds)<br>{<br>    $srid = env(&#39;SPATIAL_REF_ID&#39;, 4326);<br><br>    [   &#39;south&#39; =&gt; $south,<br>        &#39;west&#39;  =&gt; $west,<br>        &#39;north&#39; =&gt; $north,<br>        &#39;east&#39;  =&gt; $east<br>    ] = $mapBounds;<br><br>    $query = Marker::<em>query</em>()<br>        -&gt;whereRaw(&quot;<br>        ST_Contains(<br>            ST_PolygonFromText(&#39;POLYGON(<br>                   ($north $west, $north $east, $south $east, $south $west, $north $west)<br>                )&#39;, {$srid}), <br>            `coordinate` <br>        )&quot;);<br><br>    return $query;<br>}</pre><p>Of course we need the SRID value again, though normally we’d probably use a config value for it, or even inject it through a service provider. For now let’s just assume that’s what we did instead of a dirty copy-paste.</p><p>The query itself takes a bit of explanation, so let me break it down:</p><pre>POLYGON(($north $west, $north $east, $south $east, $south $west, $north $west))</pre><p>First, in the innermost part of the query, we use the $mapBounds values we extracted to create our Polygon. If you’re wondering if you miscounted, yes we are using 4 distinct values to fill 10 values in the query. From the 2 coordinates we can easily determine the other 2 corners of the rectangle. That still leaves 2 values, which are basically the first 2 values repeated. You always need to “close” a polygon, so the starting point must always match the end point.</p><p>If we move up one step we get ST_PolygonFromText that simply converts our textual representation of a polygon into an actual geometry value.</p><p>One more step up and we get the absolutely brilliantST_Contains function. <br>The only input this function requires if a polygon within which it must search, and a coordinate to search for. The coordinate in this case is simply the column of our markers table. The polygon is the one we just created.</p><p>And that is all you need really. These methods combined will used the indexed spatial column to search within the generated geometry. The geometry itself is generated for each record, but the impact of that is negligible. However there are ways to generate it one time, then using the previously generated value to calculate the matching points.</p><p>The demo code also contains the possibility to add in a list of marker id’s to exclude from the search, because there is no need to fetch the same markers we’ve already fetched before. We’ll briefly come to that when I explain the frontend code.</p><p>Last part to actually fetch the data is the controller method, which is obviously quite small:</p><pre>public function getLocations(MapRequest $request, LocationFinderService $finderService)<br>{<br>    if(!$request-&gt;validated()) {<br>        throw new InvalidArgumentException(&#39;Invalid map bounds&#39;);<br>    }<br><br>    $markers = $finderService-&gt;findByBounds(<br>        $request-&gt;getMapBounds()<br>    );<br><br>    return MarkerResource::<em>collection</em>(<br>        $markers-&gt;paginate(100)<br>    );<br>}</pre><p>The MapRequest class simply guarantees the $mapBounds array we discussed earlier. Then all we need to do is provide that data to the LocationFinderService. If you were paying attention, you noticed the service returns a Builder instance which allows us to do stuff like pagination from the controller.</p><h3>Step 5: Show me the mo… map!</h3><p>We have most of the backend code ready now, so let’s move to the frontend.</p><p>Being a bit lazy, instead of creating a new view file, I’ve simply changed the default welcome.blade.php:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;{{ str_replace(&#39;_&#39;, &#39;-&#39;, app()-&gt;getLocale()) }}&quot;&gt;<br>    &lt;head&gt;<br>        &lt;meta charset=&quot;utf-8&quot;&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;<br>        &lt;meta name=&quot;csrf-token&quot; content=&quot;{{ csrf_token() }}&quot;&gt;<br>        &lt;title&gt;Polygonal location search demo&lt;/title&gt;<br>        &lt;link rel=&quot;stylesheet&quot; href=&quot;https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css&quot; integrity=&quot;sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T&quot; crossorigin=&quot;anonymous&quot;&gt;<br>    &lt;/head&gt;<br>    &lt;body class=&quot;bg-light&quot;&gt;<br>        &lt;div class=&quot;container&quot;&gt;<br>            &lt;div class=&quot;py-5 text-center&quot;&gt;<br>                &lt;h1&gt;Polygonal map search demo&lt;/h1&gt;<br>                &lt;p class=&quot;lead&quot;&gt;<br>                    A demo of the power of MySQL 8 for searching Points within a Polygon for mapping purposes.<br>                &lt;/p&gt;<br>            &lt;/div&gt;<br>            &lt;div class=&quot;d-flex justify-content-center&quot; id=&quot;app&quot;&gt;<br>                &lt;demo-map :lat=&quot;50.884408&quot; :lon=&quot;5.756073&quot; :zoom=&quot;16&quot;&gt;&lt;/demo-map&gt;<br>            &lt;/div&gt;<br>        &lt;/div&gt;<br>        &lt;script src=&quot;{{ mix(&#39;js/app.js&#39;) }}&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;<br>    &lt;/body&gt;<br>&lt;/html&gt;</pre><p>Not much happening here except loading in the Bootstrap CDN code for an easy start without needing to write any CSS. Tailwind would have done the job as well of course. Just work with what you know or like best.</p><p>Being familiar with VueJS you’ll notice the main component here is demo-map.<br>We pass on two props to the component that represent the centre of the map. <br>For your purposes you probably want to change this to whatever your own location is.</p><p><strong>NB</strong>: If you are wondering why I use <a href="https://vuejs.org/v2/guide/components-props.html#Passing-Static-or-Dynamic-Props">dynamic props here</a> (using the short version of <a href="https://vuejs.org/v2/api/#v-bind">v-bind</a>), the reason is that we’re passing floats. If I did not do this, the resulting props in the component would become strings.</p><p>The rest of the template is nothing more than a bit of basing and the inclusion of the actual application JavaScript code.</p><h4>The DemoMap component</h4><p>Which brings us to the demo-map itself:</p><pre>&lt;template&gt;<br>    &lt;div&gt;<br>        &lt;div class=&quot;google-map&quot; id=&quot;map&quot;&gt;&lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;/template&gt;</pre><p>It starts with a very easy template that’s nothing more than a Google Maps div. And we’re using a small bit of custom styling, because Google Maps doesn’t really like dynamic sizing:</p><pre>&lt;style&gt;<br>    #map {<br>        margin: 0 auto;<br>        height: 600px;<br>        width: 800px;<br>    }<br>&lt;/style&gt;</pre><p>But most of this is window dressing. The actual fun happens here:</p><pre>import GoogleMaps from &quot;../GoogleMaps&quot;;<br>import debounce from &quot;tiny-debounce&quot;;<br>import axios from &quot;axios&quot;;<br><br>export default {<br>    props: {<br>        zoom: {<br>            type: <strong><em>Number</em></strong>,<br>            default: 8<br>        },<br>        lat: {<br>            type: <strong><em>Number<br>        </em></strong>},<br>        lon: {<br>            type: <strong><em>Number<br>        </em></strong>}<br>    },<br>    data() {<br>        return {<br>            googleMapsKey: <strong><em>process</em></strong>.env.MIX_GOOGLE_MAPS_KEY,<br>            loaded: false,<br>            map: null,<br>            markers: {},<br>            markerIds: {},<br>            page: 1,<br>            search: null<br>        }<br>    },<br>    mounted() {<br>        this.load();<br>    },<br>    methods: {<br>        fetchMarkers(postData) {<br>            return axios.post(&#39;find-markers&#39;);<br>        },<br>        fetchMarkersInBounds(mapBounds) {<br>            let that        = this;<br>            this.page       = 1;<br>            this.properties = [];<br><br>            this.fetchMarkers({<br>                &#39;north&#39; : mapBounds.north,<br>                &#39;south&#39; : mapBounds.south,<br>                &#39;east&#39;  : mapBounds.east,<br>                &#39;west&#39;  : mapBounds.west,<br>            })<br>            .then(response =&gt; {<br>                let {data: {data: markers, links}} = response;<br><br>                if (links.prev === null) {<br>                    that.page = 1;<br>                }<br><br>                if (markers.length &gt; 0) {<br>                    that.page += 1;<br>                    that.loadMarkers(markers);<br>                }<br><br>                that.links = links;<br><br>                if (typeof that.links.next !== &#39;undefined&#39; &amp;&amp; that.links.next !== null) {<br>                    that.fetchMarkersInBounds(mapBounds);<br>                }<br>            });<br>        },<br>        async load() {<br>            this.loaded = true;<br><br>            await GoogleMaps.<em>load</em>(this.googleMapsKey, &quot;EN&quot;, &#39;en&#39;);<br><br>            this.initMap();<br>        },<br>        loadMarkers(markers) {<br>            for (let i = 0; i &lt; markers.length; i++) {<br>                let marker = markers[i];<br><br>                this.markerIds[marker.id] = true;<br><br>                if(marker.hasOwnProperty(&#39;coordinates&#39;) &amp;&amp; !this.markers.hasOwnProperty(marker.id)) {<br>                    this.createMarker(marker);<br>                }<br>            }<br>        },<br>        createMarker(item) {<br>            let position = new google.maps.LatLng(item.coordinates.lat, item.coordinates.lon);<br><br>            this.markers[item.id] = new google.maps.Marker({<br>                position: position,<br>                map: this.map<br>            });<br>        },<br>        initMap() {<br>            this.map = new google.maps.Map(<strong><em>document</em></strong>.getElementById(&#39;map&#39;), {<br>                zoom  : this.zoom,<br>                center: new google.maps.LatLng(this.lat, this.lon),<br>                streetViewControl: false,<br>                mapTypeControl: false,<br>                fullscreenControl: false<br>            });<br><br>            this.map.addListener(&#39;bounds_changed&#39;, () =&gt; {<br>                this.boundsChanged();<br>            });<br>        },<br>        boundsChanged: debounce(function() {<br>            this.fetchMarkersInBounds(this.map.getBounds().toJSON());<br>        }, 500),<br>    }<br>};</pre><p>I will break this down in it’s constituent components.</p><pre>async load() {<br>    await GoogleMaps.<em>load</em>(this.googleMapsKey, &quot;EN&quot;, &#39;en&#39;);</pre><pre>this.loaded = true;<br>    this.initMap();<br>},</pre><p>I have a small GoogleMaps helper class created by <a href="https://medium.com/u/60b58299a4">Patrick Brouwers</a>. It basically loads the GoogleMaps library within a Promise so we can load it when needed. It’s included in the demo code, but I won’t go into it here.</p><p>The load function is called once, through the mounted hook. initMap then loads the actual map.</p><pre>initMap() {<br>    this.map = new google.maps.Map(<strong><em>document</em></strong>.getElementById(&#39;map&#39;), {<br>        zoom  : this.zoom,<br>        center: new google.maps.LatLng(this.lat, this.lon),<br>        streetViewControl: false,<br>        mapTypeControl: false,<br>        fullscreenControl: false<br>    });</pre><pre>    this.map.addListener(&#39;bounds_changed&#39;, () =&gt; {<br>        this.boundsChanged();<br>    });<br>}</pre><p>Most of this code is vanilla JavaScript or course, because that’s how the maps library works. But if you use Maps a lot, you may want to use or make a dedicated component for that. There are a few on Github.</p><p>We initialize an instance of google.maps.Map and bind it to our component instance. The lat and lon props we provide from the main blade file are used to centre the map. The zoom can also be set through the props, but it has a default value of 16.</p><p>Then we add a listener to the bounds_changed event. Google Maps will trigger this event whenever the visible bounds are changed. This happens when the map is loaded, the size is changed or when you scroll or zoom the map. <br>When that happens we trigger our won boundsChanged method:</p><pre>boundsChanged: debounce(function() {<br>    this.fetchMarkersInBounds(this.map.getBounds().toJSON());<br>}, 500),</pre><p>This will fetch the bounds from the map instance and convert it into JSON to use in our fetchMarkersInBounds method.</p><pre>fetchMarkersInBounds(mapBounds) {<br>    let that        = this;<br>    this.page       = 1;<br>    this.properties = [];</pre><pre>    this.fetchMarkers({<br>        &#39;north&#39; : mapBounds.north,<br>        &#39;south&#39; : mapBounds.south,<br>        &#39;east&#39;  : mapBounds.east,<br>        &#39;west&#39;  : mapBounds.west,<br>    })<br>    .then(response =&gt; {<br>        let {data: {data: markers, links}} = response;</pre><pre>        if (links.prev === null) {<br>            that.page = 1;<br>        }</pre><pre>        if (markers.length &gt; 0) {<br>            that.page += 1;<br>            that.loadMarkers(markers);<br>        }</pre><pre>        that.links = links;</pre><pre>        if (typeof that.links.next !== &#39;undefined&#39; &amp;&amp; that.links.next !== null) {<br>            that.fetchMarkersInBounds(mapBounds);<br>        }<br>    });<br>},</pre><p>This takes the mapBounds object we just fetched from the map instance and passes it through the fetchMarkers method. Then when the promise of that method finishes it will add the markers to the component instance and set the links, and page accordingly (as you have seen before we are using pagination).</p><pre>fetchMarkers(postData) {<br>    if(this.markerIds) {<br>        postData.markerIds = <strong><em>Object</em></strong>.keys(this.markerIds);<br>    }</pre><pre>    return axios.post(&#39;find-markers&#39;, postData);<br>},</pre><p>The fetchMarkers method simply adds the already existing markers to the postData and then uses axios to request a new list of markers from the api endpoint we created earlier.</p><pre>loadMarkers(markers) {<br>    for (let i = 0; i &lt; markers.length; i++) {<br>        let marker = markers[i];</pre><pre>        this.markerIds[marker.id] = true;</pre><pre>        if(marker.hasOwnProperty(&#39;coordinates&#39;) &amp;&amp; !this.markers.hasOwnProperty(marker.id)) {<br>            this.createMarker(marker);<br>        }<br>    }<br>},</pre><p>The loadMarkers method loops over the markers received from the API, then adds the id’s to a list (which we use in fetchMarkers to make sure we don’t receive the same marker twice). It then checks if the marker has coordinates, doesn’t already exist, and if both of these statements are true, it will create the marker on the map.</p><pre>createMarker(item) {<br>    let position = new google.maps.LatLng(item.coordinates.lat, item.coordinates.lon);</pre><pre>    this.markers[item.id] = new google.maps.Marker({<br>        position: position,<br>        map: this.map<br>    });<br>},</pre><p>Finally we’ve reached the point where the marker will be shown on the map itself. We bind the created marker to this.markers to keep a reference to all markers in case you need to access them later of need to remove them from the map.</p><p>A few side notes here:</p><ul><li>The actual demo code also contains a method to do a search by location which will centre the map on the location it finds, and because that changes the map bounds, it will also trigger an API call to find markers in that area.</li><li>I’ve used <a href="https://github.com/vuejs-tips/tiny-debounce">tiny-debounce</a> in the boundsChanged method to minimize the amount of calls to the API. You can also use the lodash version or any other similar method. Or even write a small setTimeout implementation.</li><li>I’m assuming you know how the Google Maps API works, so I haven’t explained things like new google.maps.Marker or new google.maps.LatLng</li><li>We’re passing the maps api key from the .env file via process.env.MIX_GOOGLE_MAPS_KEY. This is basic Laravel+Vue+Mix magic. Not something I had anything to do with.</li></ul><h3>The end result</h3><p>All of these steps combined have created something similar to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*2E7iDPkj1TSpCLY9GMC1TQ.png" /></figure><p>Take a look at the demo project on <a href="https://github.com/jochemfuchs/mysql8-polygonal-geolocator">Github</a> for the full code and some extra’s. And feel free to contact me for questions on any details.</p><p>Written by <a href="https://twitter.com/jochemfuchs">Jochem Fuchs</a>, Software engineer at <a href="https://www.maatwebsite.nl/">Maatwebsite</a></p><p>Do you need help working with geolocation in your app or do you need help building a Laravel application? At <a href="https://www.maatwebsite.nl/?source=post_page---------------------------">Maatwebsite</a>, we are there to help you on a commercial basis. Contact us via <a href="/service/mailto:info@maatwebsite.nl?source=post_page---------------------------">info@maatwebsite.nl </a>or via phone +31 (0)10 744 9312 to discuss the possibilities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3caeb614ffd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/mysql-8-polygonal-map-search-f3caeb614ffd">MySQL 8 Polygonal map search</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MySQL 8 and maps. A power combo?]]></title>
            <link>https://medium.com/spartner/mysql-8-and-maps-a-power-combo-cb33f62168ef?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/cb33f62168ef</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[geolocation]]></category>
            <dc:creator><![CDATA[Jochem Fuchs]]></dc:creator>
            <pubDate>Wed, 07 Aug 2019 12:01:01 GMT</pubDate>
            <atom:updated>2019-08-07T12:01:01.152Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q0B8zToJQvZPJ9bA-a2DNQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@dead____artist?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Capturing the human heart.</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Some time ago I wrote a blog about “<a href="https://medium.com/maatwebsite/the-best-way-to-locate-in-mysql-8-e47a59892443">The best way to locate, in MySQL 8</a>”. In that article I promised to follow up with some metrics to show how MySQL 8 performs. I’ve been dragging my feet, for the simple reason that I don’t believe it would be a very interesting read. Feel free to leave a comment if you think otherwise!</p><p>Instead, let’s have some fun with a practical example we’re going to build together!</p><h3>What are we making?</h3><p>You’ve probably all seen them and have used them many times with varying results. Whether you’re looking for stores, real estate or a place to stay, they all work on the same principle. You’re looking for location based items, and you want to be able to scroll through the map to find more.</p><p>In <a href="https://www.funda.nl/en/kaart/koop/meerssen/">some cases</a> these maps are lightning fast, but in <a href="https://www.airbnb.nl/s/Meerssen--Netherlands/homes">many cases</a> it actually takes a few seconds to load the results on the map.</p><p>We’ll first take a look into why that is, then we’ll discuss some often used optimisations to mitigate that, and finally I’ll guide you through building a solution that is fast without any of those optimisations.</p><h3>So why is the traditional approach slow?</h3><p>In a database without (or with limited) spatial functions and without using optimisation or caching techniques, you would have to calculate the distance of each point in your database from the centre of the currently visible map. Scrolling the map would restart that entire process each time.</p><p>If you’ve read my previous article, you know I mentioned the <a href="https://en.wikipedia.org/wiki/Haversine_formula">Haversine formula</a>. It’s this formula that is calculated for EACH and EVERY point in your database, at EVERY request. We’re disregarding caching for now, as this does not solve the issue, just mitigates the resulting slowness to some extent.</p><p>Let’s have a quick look into how this would look:</p><pre>SELECT *<br> ,(6371 * Acos(Cos(Radians(map_center_latitude)) * Cos(Radians(lat)) * Cos(Radians(lng) - Radians(map_center_longitude)) + Sin(Radians(map_center_latitude)) * Sin(Radians(lat)))) AS distance<br>FROM locations<br>HAVING distance &lt; 25<br>ORDER BY distance;</pre><p>Now apart from the actual formula being very hard to read, you can quickly see the issue here. For each row in the database it would need to calculate the distance to the map_center. Then the results of that calculation are sorted and those that match the HAVING clause are returned.</p><p>Even with indexing of lat and lon you’d still see the database scanning all rows. You can see this when we use EXPLAIN:</p><pre>EXPLAIN SELECT * ,(6371 * Acos(Cos(Radians(map_center_latitude)) * Cos(Radians(lat)) * Cos(Radians(lon) - Radians(map_center_longitude)) + Sin(Radians(map_center_latitude)) * Sin(Radians(lat)))) AS `distance` FROM `locations` HAVING `distance` &lt; 25 ORDER BY `distance`\G<br>*************************** 1. row ***************************<br>           id: 1<br>  select_type: SIMPLE<br>        table: locations<br>   partitions: NULL<br>         type: index<br>possible_keys: NULL<br>          key: lat_2<br>      key_len: 10<br>          ref: NULL<br>         rows: 9980<br>     filtered: 100.00<br>        Extra: Using where; Using index; Using filesort<br>1 row in set, 1 warning (0.00 sec)</pre><p>Now imagine having to do this same query over and over, with only the map_center changing. Even with some kind of debounce solution in the frontend and caching in the backend, it will always feel sluggish.</p><h3>Ok, but some maps are very fast, how?</h3><p>There are many ways to approach this, but most of them will be some form of caching, preloading or even NoSQL solutions. <br>Let’s quickly run through a few of the options and their downsides.</p><ol><li><strong>Caching</strong><br>This seems like the obvious first step. It’s quick, and it’s easy to implement in most frameworks like Laravel. But how would you implement caching if your only variable is every possible coordinate within your search area? In the end, this solution isn’t really viable.</li><li><strong>Preload all the things!</strong><br>While I haven’t been able to prove it, some of the maps I’ve studied for this article seem to load with the entire list of markers already there. There is no additional loading when scrolling, it’s just already there. And this is probably a perfect solution if you have a fairly limited area to search (though the Netherlands seems to be small enough), and with a set of points that don’t change very often and can therefore be cached easily. <br>The limit, of course, is the size of the dataset. The bigger that is, the longer it will take for the frontend to load and interpret it. Until at some point you reach a tipping point and suddenly your frontend is the bottleneck. And you can’t really control the different browsers and internet connections the end users will possess.</li><li><strong>NoSQL / ElasticSearch / Algolia and others</strong><br>This is a well known and very viable solution for our problem. Many of these kinds of services/systems have built-in features for quickly searching in location based data. And if you’re already using something like this, then there really is no need for looking any further. <br>If you aren’t already using such a system, then the investment of implementing one might not be worth it. After all, the location based searching is just one of many features they offer, and many of these services are paid subscriptions, or they might simply be very expensive to run and implement yourself. That’s budget you might not have or a system you might not be able to support.</li><li><strong>PostgreSQL with PostGis<br></strong>Ok, so this is cheating a bit. If you have the know-how and experience to use PostgreSQL, then by all means go for it. In fact ALMOST ALL of the advantages MySQL 8 offers over older versions have already existed in PostgreSQL for a long time. <br>So what’s the downside you may ask? It’s still a niche product, relatively speaking. There is far less information, far less tools, and a far smaller community than there is for MySQL. The learning curve is steeper and if you don’t already have experience with it, it’s most likely too costly to implement it for a fairly simple feature like we’re going to build here. <br>But that’s pretty much the only downside I can think of. So if you do have the knowledge and experience, you’re pretty much set and you can probably follow my guide here and implement the same app with PostgreSQL as well.</li></ol><h3>So where does MySQL 8 come in?</h3><p>Well I’m glad you asked! Next week we’ll continue with a quick tutorial to build a demo implementation of this concept. The end result will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*_UWJUAO6Q6o3oIWDIHgQWQ.png" /></figure><p>Written by <a href="https://twitter.com/jochemfuchs">Jochem Fuchs</a>, Software engineer at <a href="https://www.maatwebsite.nl/">Maatwebsite</a>.</p><p>Do you need help working with geolocation in your app or do you need help building a Laravel application? At <a href="https://www.maatwebsite.nl/?source=post_page---------------------------">Maatwebsite</a>, we are there to help you on a commercial basis. Contact us via <a href="/service/mailto:info@maatwebsite.nl?source=post_page---------------------------">info@maatwebsite.nl </a>or via phone +31 (0)10 744 9312 to discuss the possibilities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb33f62168ef" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/mysql-8-and-maps-a-power-combo-cb33f62168ef">MySQL 8 and maps. A power combo?</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Laravel and Murphy’s Law]]></title>
            <link>https://medium.com/spartner/laravel-and-murphys-law-e22731be31d9?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/e22731be31d9</guid>
            <category><![CDATA[law-of-murphy]]></category>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Patrick Brouwers]]></dc:creator>
            <pubDate>Mon, 22 Jul 2019 14:34:02 GMT</pubDate>
            <atom:updated>2019-07-22T14:34:02.319Z</atom:updated>
            <content:encoded><![CDATA[<p>“Whatever can go wrong, will go wrong”, states the well known Murphy’s Law. Lots of people will be able to relate to this popular adage, but especially in software this is a law to take into account: hope for the best, but be prepared for the worst.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*GJGFUnhHp98SkM10LewyOQ.png" /></figure><h3>Murphy’s Law and Software Design</h3><p>When designing software, it’s always good to think about how to recover a situation that goes wrong. Especially when dealing with external APIs the fault may not even be caused by your code, but — as we learned from Murphy’s Law — we should prepare for the worst. An external API could timeout, give a slowdown response (503 — rate limit exceeded), have a breaking change, … A lot of things can go wrong.</p><p>Let’s have a look at how we could tackle these issues in Laravel.</p><h3>Encapsulating in Queued Jobs</h3><p>When dealing with external API calls, it might be wise to separate those calls into their own processes. Laravel has a great way of encapsulating them: queued jobs. Jobs have a couple of benefits:</p><ul><li>The process is asynchronous (it happens in the background).</li><li>It can automatically attempt the job multiple times.</li><li>The job can be manually retried.</li><li>Insight into why this specific job has failed.</li></ul><h4>The basics of using Queued Jobs in Laravel</h4><p>A job in Laravel is nothing different from a simple PHP class with a handle() method. We indicate that it should be queued by adding the ShouldQueue interface. Whatever happens within the handle method will be executed when the job is popped from the queue.</p><pre>class CallExternalApi implements ShouldQueue<br>{<br>    public function handle(ExternalApi $externalApi)<br>    {<br>        $externalApi-&gt;call();<br>    }<br>}</pre><p>We can dispatch the job onto the queue by using the dispatch helper:</p><pre>dispatch(new CallExternalApi);</pre><p>The queue worker can be ran by using the queue:work artisan command.</p><pre>php artisan queue:work</pre><p>The command line will display that the job has been processed:</p><pre>[2019-06-26 14:03:26][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:26][12] Processed:  App\Jobs\CallExternalApi</pre><h3>When things go wrong</h3><p>As Murphy’s Law states: things will go wrong. When the job fails we see that by default Laravel keeps retrying without any delay.</p><pre>[2019-06-26 14:03:26][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:27][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:28][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:29][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:20][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:31][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:32][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:33][12] Processing: App\Jobs\CallExternalApi<br>...</pre><h4>Limiting retries</h4><p>One solution to this problem is by limiting the number of retries, the quickest approach to this is by specifying it on the artisan command.</p><pre>php artisan queue:work --tries=3</pre><p>Now when the queue has tried 3 times, it will mark the job as failed.</p><pre>[2019-06-26 14:03:26][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:27][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:28][12] Processing: App\Jobs\CallExternalApi<br>[2019-06-26 14:03:29][12] Failed:     App\Jobs\CallExternalApi</pre><h4>Notifying the user of the failure</h4><p>Laravel has a way to hook into failing jobs by using the failed() method on the job class. You could use that hook to notify the user of the failure, send a text message to yourself that things are going wrong, etc. The hook will only run after the last retry.</p><pre>class CallExternalApi implements ShouldQueue<br>{<br>    public function __construct(User $user)<br>    {<br>         $this-&gt;user = $user;<br>    }</pre><pre>    public function handle(ExternalApi $externalApi)<br>    {<br>        $externalApi-&gt;call();<br>    }</pre><pre>    public function failed()<br>    {<br>        $this-&gt;user-&gt;notify(new ExternalApiCallFailedNotification);<br>    }</pre><h4>Retrying jobs</h4><p>Laravel can save all failed jobs into the database. First, you have to create the <em>failed_jobs</em> table by running:</p><pre>php artisan queue:failed-table<br>php artisan migrate</pre><p>The <em>failed_jobs</em> table contains information about the connection, the queue, the payload and the exception that was thrown.</p><p>We can view all failed jobs by running queue:failed:</p><pre>php artisan queue:failed</pre><p>This command will show you the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*SXYo2GuUCq6DuuvnOjb0Mw.png" /></figure><p>The database tables shows more information like the payload and the thrown exceptions. This can also be displayed by using <a href="https://horizon.laravel.com/">Laravel Horizon</a>.</p><p>By keeping this information, Laravel allows us to retry the job at a later time. This might be handy when there was a software bug in the job code. After deploying the bugfix, we can retry the job by running thequeue:retry command.</p><pre>php artisan queue:retry 1</pre><p>The job (with id 1) will now be pushed back onto the queue and ran by the queue worker.</p><h3>Automating the retry process</h3><p>It might not always be necessary to retry a job manually. An external API can give a timeout or a slowdown response (503)— in those situations we want to automatically retry multiple times, but with a delay between the attempts.</p><h4>Delaying attempts</h4><p>Laravel allows us to define a global delay for all jobs handled by the same worker by specifying the --delay option:</p><pre>php artisan queue:work --tries=3 --delay=3</pre><p>Now the queue worker will wait 3 seconds before retrying a failed job.</p><h4>Situation specific retries and delays</h4><p>By using the command line options, we specify the tries and the delay for all jobs. In some situations, this might not be enough. Some jobs are allowed to have more tries or need to have a bigger delay. Laravel allows us to specify those settings on the job class:</p><pre>class CallExternalApi implements ShouldQueue<br>{<br>     use InteractsWithQueue;</pre><pre>     /**<br>     * The number of times the job may be attempted.<br>     *<br>     * @var int<br>     */<br>    public $tries = 5;</pre><pre>   /**<br>    * The number of seconds to wait before retrying the job.<br>    *<br>    * @var int<br>    */<br>    public $retryAfter = 5;<br>}</pre><p>If these settings are specified on the job, it will take precedence over the value provided on the command line.</p><h4>Exponential backoff strategy</h4><p>In situations like a slowdown response (503) of the external API, it might be necessary to increase the delay after each attempt. Laravel allows this by specifying a retryAfter() method on the job class. <br>Via theInteractsWithQueue trait, we can retrieve the number of attempts.</p><pre>class CallExternalApi implements ShouldQueue<br>{<br>    use InteractsWithQueue;</pre><pre>    /**<br>     * The number of times the job may be attempted.<br>     *<br>     * @var int<br>     */<br>    public $tries = 10;</pre><pre>    /**     <br>     * @return Carbon     <br>     */    <br>     public function retryAfter()    <br>     {   <br>         return now()-&gt;addSeconds(            <br>             $this-&gt;attempts() * 2      <br>         );    <br>     }<br>}</pre><p>The above example will increase the delay with a linear curve. If we want to implement an exponential approach, we can use the exponential backoff formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/116/1*9xL_KAWEPzwXF2wWyRHStQ.png" /><figcaption>Exponential backoff formula</figcaption></figure><p>In Laravel we would implement it as follows:</p><pre>public function retryAfter()    <br>{   <br>    return now()-&gt;addSeconds(            <br>        (int) round(((2 ** $this-&gt;attempts()) - 1 ) / 2)        <br>    );    <br> }</pre><p>Now the retry time will grow exponentially until the max attempts are reached as shown in this diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*BfugUl9Vdpe5GqJcJNj-pg.png" /><figcaption>Delay (in seconds) vs Attempts</figcaption></figure><blockquote>Note: if you want to have a lot of retries using an exponential backoff, it will quickly have hour-long retry delays. In those cases you might want to look into using a logarithmic function.</blockquote><h3>Conclusion</h3><p>When designing software, don’t only think about the happy path. Write down (preferably with (unit) tests) what all the things are that could go wrong. Then design your solution to be able to recover those situations. (Wether or not automatic.) There isn’t a single solution to rule them all, some processes might need to have specific failure handling while others are fine with the default approach.</p><p>Do you need help implementing retry strategies in your project or do you need help building a Laravel application? At <a href="https://www.maatwebsite.nl/">Maatwebsite</a>, we are there to help you on a commercial basis. Contact us via <a href="/service/mailto:info@maatwebsite.nl">info@maatwebsite.nl </a>or via phone +31 (0)10 744 9312 to discuss the possibilities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e22731be31d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/laravel-and-murphys-law-e22731be31d9">Laravel and Murphy’s Law</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Methodology or dogma]]></title>
            <link>https://medium.com/spartner/methodology-or-dogma-a-plea-for-common-sense-6a10b0dd8591?source=rss----52af03c2915c---4</link>
            <guid isPermaLink="false">https://medium.com/p/6a10b0dd8591</guid>
            <category><![CDATA[methodology]]></category>
            <category><![CDATA[methods]]></category>
            <category><![CDATA[dogma]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[free-thinking]]></category>
            <dc:creator><![CDATA[Jeroen Vossen]]></dc:creator>
            <pubDate>Fri, 21 Jun 2019 09:44:20 GMT</pubDate>
            <atom:updated>2019-07-26T10:10:01.920Z</atom:updated>
            <content:encoded><![CDATA[<h3>Methodology or dogma in software development, a plea for common sense</h3><p><em>Alarm bells ringing</em>….. “ did I really just hear a scrum master say, in a discussion about the duration of a sprint, that it should be in weeks and not in calendar months because in scrum sprints are in weeks???”</p><p>Do you really only want to do something because it is written in a book? History proves it is risky business if people apply a dogmatic approach and follow books or ‘leaders’ blindly.</p><p>Of course it is perfectly logical that people seek ‘guidance’ when they try to accomplish an objective. Therefore it is also logical that systems (like methodologies) have emerged to help people.</p><h3>Why are there methodologies?</h3><p>Most of the time people do not do things just randomly, but have a goal they want to achieve. In order to achieve any goal, one has to perform several actions. The quality of performing these actions that you perform these actions can determine the success rate in achieving the goal.</p><p>People generally don’t just start doing something in an effort to accomplish a goal, but they use a methodology that offers structure and support. A methodology combines a combination of methods in order to do so.</p><h3>Methodology versus framework</h3><p>So far I have only used the term methodology, but the terms methodology and framework are often used interchangeably However, there is a clear distinction:</p><ul><li>Methodology: a set of principles, tools and practices which can be used to guide processes to achieve a particular goal.</li><li>Framework: a real or conceptual structure intended to serve as a support or guide for the building of something that expands the structure into something useful.</li></ul><p>The main difference is that a methodology is much more prescriptive than a framework, it has a more clear set of rules which should be followed in a particular order.</p><p>A framework on the other hand is of a more liberal character and offers more room for creativity, with the result that it is more ambiguous.</p><h3>Why I prefer a framework</h3><p>I personally favour a framework, as the key component in the definition is the word “supporting”. It should help you achieve a certain goal. It should provide you with guidelines on how to approach the process, or offer elements that can be helpful.</p><p>It should <strong>not</strong> dictate which steps should be followed. Use the elements that help, and discard the ones that do not.</p><p>In my opinion, this gives you more adaptability in contrast to a more rigid methodology.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s7Zf8PkbeXP_54NC" /></figure><p>Most of the time, our environment and the discipline we work in is of a complex nature. The rigidity of a methodology is in my opinion a limiting factor. The flexibility of a framework offers the agility needed to adapt to this complexity.</p><h3>So what now?</h3><p>Abundance is everywhere in the western world. If you don’t believe me, take a look at this (undoubtedly incomplete) list of Android based smartphones: <a href="https://en.wikipedia.org/wiki/List_of_Android_smartphones">https://en.wikipedia.org/wiki/List_of_Android_smartphones</a></p><p>The same goes for methodologies and frameworks in (project) management and software development, and the overlapping realm. Over the years, countless new methodologies have been introduced, sometimes based on new insights or in order to adapt to a changing world. But often it is merely old wine in new bottles. The sheer abundance should be a clear sign that no single methodology offers you the holy grail.</p><p>Besides that, methodologies are big business for a lot of consultancy and training firms, creating so called “certified” specialists, <em>blabla</em> masters, ninjas, evangelists etc.</p><p>The sign of a money generating business is when they are treated like a religion.</p><p>There are some elements that I often use</p><ul><li>Think for yourself, be a freethinker</li><li>Use what helps YOU to achieve YOUR goal</li><li>KISS (Keep It Simple Stupid), or as Einstein said: Everything should be made as simple as possible, but not simpler.</li><li>Use books and its rules as inspiration, not as a dogma.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dR_BMOrP7JBhHtQa" /></figure><p>In other words, use common sense (or “boerenverstand” as we call it in Dutch). I think it is important to think for yourself. The grey matter in your head should be used for being open minded, being critical and being inquisitive, instead of being used to just blindly follow someone else’s ideas.</p><p>This blog represents my personal opinion based on over 25 years experience in (project) management. You are free to disagree and I welcome discussion, as long as it is of constructive nature.</p><p><a href="https://www.linkedin.com/in/jeroenvossen/">Jeroen Vossen</a>, Team manager @ <a href="http://www.maatwebsite.nl/">Maatwebsite</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a10b0dd8591" width="1" height="1" alt=""><hr><p><a href="https://medium.com/spartner/methodology-or-dogma-a-plea-for-common-sense-6a10b0dd8591">Methodology or dogma</a> was originally published in <a href="https://medium.com/spartner">Spartner</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>