Similar Posts
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…
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…
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,…
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…
Running Artisan Command as a Separate PHP Process in Laravel
In Laravel framework you can create commands and call them from php application. One command can call another command, and another command, and so on. But if an exception is thrown in one of the commands in this chain the whole chain breaks. In order to avoid this problem and run each artisan command as…