Category: PHP MySQL Development

  • Custom Mail Driver for Laravel

    Custom Mail Driver for Laravel

    Out of the box Laravel supports many mail drivers, such as smtp, sendmail, mailgun, log, array, etc. But what if you wold like to use a mail service that Laravel does not have a driver for, such as Mailjet?  You can create a custom driver for that service.  This article will describe how to create…

  • API Client Design

    API Client Design

    When you extensively work with certain APIs, like Shopify’s for example, you will end up with bunch of functions that map to API’s endpoints. One of the approaches I have seen so far is to create an API class ShopifyApi and make those functions class methods. So it looks something like the figure below. I…

  • SSH Key Set Up for Multiple GitHub Accounts

    A great article on how to set up and manage ssh keys for multiple github accounts/repositories SSH Keys with Multiple GitHub Accounts

  • Extracting SKUs from Shopify Products

    Let’s assume we have a use case. We create products at someotherwebsite.com. In the end of each day we want to sync newly created products to Shopify store using API. Each product that we are creating has a unique code to identify it. This code corresponds to Shopify product’s sku. This is how we link…

  • Debugging Webhooks

    Debugging Webhooks

    A webhook is an HTTP callback, that occurs when something happens (a resource changes its state). Webhooks provide a way to build event-driven apps, because you can be notified about changes. Since webhooks require a publicly accessible URL to function they can be hard to test from your local machine.  There are three main problems…

  • Mailroom Clerk

    Mailroom Clerk

    Download for Windows: mailroom-clerk-win32-ia32 Download for Mac: mailroom-clerk-darwin-x64

  • Replace Funky Characters While Importing CSV

    Sometimes uploaded text/csv file may have non-utf8 or other funky characters using the function below. public static function processUploadedBundles($request) { $content = file_get_contents($request->file(‘uploadedFile’)->getRealPath()); $lines = explode(PHP_EOL, $content); $array = []; foreach ($lines as $line) { $arrayCsv = str_getcsv($line, “,”); $arrayCsv = array_map(function($value){ return preg_replace(‘/[\x00-\x1F\x7F-\xFF]/’, ”, $value); }, $arrayCsv); $array[] = $arrayCsv; } return $array; }

  • Stream Filter

    In php one can use filters with streams.  Sometimes it can become handy.  Let’s say you open a .csv file as a stream, but this file is tab separated.  Your program can can process coma separated csvs, but not tab separated.  This is a good use case for a stream filter, because it can make replacements…

  • Large CSV Export

    Sometimes you need to export a large amount of data from your database.  Obviously, if you are going to accumulate all data in an array and then write it to a csv file, you will eventually run out of memory.  A better solution is to use streams.  Here is how you can export data from…

  • Complex Eloquent Query

    A query below selects products that need to be updated in a remote application. It takes quantities of products in host application that are connected to source products application. On top of that it looks at all the orders that are in “Pending” status and reserves quantities for those products. SELECT products.quantity_available, connector_products.stock_id, products.id, connector_products.sku,…