Load does not work for dynamical relationships?

Imagine you have the following two relations:

 * Relation working/holiday/.. hours
 * @return [type] [description]
public function relatedHours($type = null)
  $type = $type ?? $this->type;
  return $this->hours()->where('type', '=', $type);

 public function workingHours()
  return $this->relatedHours(Type::WORK);

Continue reading "Load does not work for dynamical relationships?"

Print from browser directly to Dymo LabelWriter

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).

Continue reading "Print from browser directly to Dymo LabelWriter"

Imap Basics

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());

Continue reading "Imap Basics"

Ajax not working in Laravel?

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>

This may return a list like this:
Continue reading "Ajax not working in Laravel?"

Foreign Keys in Laravel

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) {


Continue reading "Foreign Keys in Laravel"