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:

  1. Saving you the time to select the correct paper-size and printer.
  2. Prevents you from accidentally printing on the Dymo (because the last printer used in the printer dialoge is most often preselected).

Read 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: ' . imap_last_error());

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:
Read more

Warn user when he leaves page

0 comments / June 7, 2019

You can create a pop-up that asks the user if he is sure that he wants to leave the page. This is used on Gmail, Facebook, Twitter, Stackoverflow, LinkedIn, etc., in all pages where you might lose data, if you accidentally close the tab.

Read more

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 create a new database for a relation:


public function up()
{
  Schema::create('logs', function (Blueprint $table) {
          $table->integer('id_user')->unsigned();
          $table->string('log');
          $table->timestamps();

          $table->foreign('id_user')
              ->references('id')->on('users')
              ->onDelete('cascade'); 
 });
}     

Read more

Best Practice For hasOne Relation in Laravel

0 comments / May 11, 2019

User hasOne Phone

You should have two tables that look somehow like this:

User Table
id name
1 Bob
Phone Table
user_id phone
1 1234567

From the user class you can access his phone as


public function phone()
{
 return $this->hasOne('App\Phone');   
}

Read 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

Read more

Background-Image for HTML Email in Outlook

0 comments / April 3, 2019

If you create a HTML email with an background image, you might be using something like this:


<td align="center" bgcolor="#F4C046" 
 style="background-image: url('../image.jpg');
        background-repeat: no-repeat;
        background-size: cover; 
        background-position:center;
        background-color:#F4C046">
  <div>
  </div>
</td>

While this is will work great in most Email-Clients, it won’t work in Outlook 2007-2016. For that you need to use Vektor Markup Language (VML), which is a feature of Microsoft which is deprecated since 2011, but its the only way that one can make background-images accessable for Outlook 2007-2016. Using VML is often refered to as “BULLETPROOF-BACKGROUNDS”, because if you use inline CSS combined with VML, then the background should work in every client.

Read more

Older