Posts in: PHP

Print from browser directly to Dymo LabelWriter

0 comments / July 27, 2019

In this post I explain how one can print immediately to the Dymo LabelWriter just by pressing a button in your web app. The printer dialog will be omitted which has two mayor benefits: Saving you the time to select the correct paper-size and printer. Prevents you from accidentally printing on the Dymo (because theRead more

Imap Basics

0 comments / July 16, 2019

I explain how to delete or move mails from a mail account through a script. First you should setup a connection. This should look like this: /* connect to server */ $hostname = ‘{123.mailserver.com:143}’; $username = ‘your@login.com’; $password = ‘top_secreted_69’; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die(‘Cannot connect to mailbox: ‘ .Read more

Ajax not working in Laravel?

0 comments / June 29, 2019

Assume you have a list of items with checkboxes: <ul class=”project-ul”> @foreach ($projects as $project) <li> <label><input type=”checkbox” value=”1″ class=”checking” data-id=”{{$project->id}}” {{($project->featured) ? ‘checked’ : ”}}> {{$project->title}}</label></li> @endforeach </ul> This may return a list like this:

Foreign Keys in Laravel

0 comments / May 14, 2019

Imagine you have a user who hasMany logs. If you delete the user, you probably don’t need the logs of him anymore. The cleanest way to automatically remove them is to use foreign keys in your database. Note that the foreign key column needs to be unsigned. Here is a clean code when you createRead more

Create database for branch and phpunit

0 comments / April 24, 2019

Whenever I work on a new branch, I find it useful to have a unique table for the branch and for my testing purposes. Lets assume we have three tables denoted in our `.env` file like that: DB_CONNECTION = mysql_local DB_DATABASE = mastertable DB_DATABASE_BRANCH = branchtable DB_DATABASE_TEST = testtable

Pivot tables don’t need an AI column

0 comments / December 8, 2018

Most scenarios are covered by a hasOne, hasMany or ManyToMany relation. How to use them is explained in detail here. I give a brief overview how they are connected to the database. User hasOne Phone You should have two tables that look somehow like this: From the user class you can access his phone asRead more

MySQL: Locks & Transactions

0 comments / November 28, 2018

Locking and transactions helps to write programs where multiple user may do simultaneous request. Lets checkout some common scenarios and how to handle them. Single Statements Two single queries will never be executed parallel. If you call