Laravel 4, Eloquent: Check if there is a Model with certain key-value pair in a Collection

Published 2013-10-17, 16:47

I wanted to find out if there already is a Model with a certain value for a certain column in a Collection that I retrieved realier in my code, e.g. is there already a User with name = Müller in my $users Collection?

$users->contains() can only check if there is a model with a certain primary key, and there also is no method to trivially search through all Models. Of course this all could be hacked together somehow*, but after a bit of searching I found this nice way to solve my question:

$value = 'Müller';
$key = 'name';
if(in_array($value, $users->lists($key))) { ... }

Collection->lists() gets an array with all the values of the Model for the requested key. Checking if our new value is in there, is super simple.

*Of course I first tried it this way:

  1. use $collection->filter() and then count the result
  2. hack $collection->contains() +$collection->find() to accept a field name as a parameter
  3. see 2, but copy the methods as private methods to my controller instead of tinkering with the framework code directly

All 3 solutions worked, but needed lots of ugly code.

PHP Frameworks

Published 2013-10-02, 11:16

As I’m getting back into working with PHP more hands-on I spent some time to look around to build this small overview of PHP frameworks. I seperated them into 3 groups: Most popular, Others and Obscure / Ancient / Dead.

Google Trends graphes

To be able to assess the popularity, these simple Google Trend charts may help:

The „old guys“

(WTH happened in October 2009?)

The „new guys“ (+ ZF for comparison)

Please note, that many people probably only search for „Zend“ to find Zend Framework.


Obscure / Ancient / Dead



Wikipedia Mobile #1

Published 2012-04-08, 02:00

This morning I accidentally installed Wikipedia’s mobile app on my iPad. It felt sluggish, strange and not at all what I expected. As bitching doesn’t help and I wanted to use my professional knowledge in my free time, I started poking around. This is the result.

Starting position

The iOS Wikipedia app has really bad ratings. Users complain about bad performance, bad usability and about the feeling that this is more an Android app but an iOS app. In sum, this creates you a rating of only 2 stars for the current version. Ouch.

Android users seem to be happier with their 4.5 star rating. The problems only exists with the iOS version of the (similar) app. Strange. Let’s start with the basics and look into the feature set:

Doesn’t sound too bad. It’s not only stuff a mobile web site could do, so an app makes sense. So lets start to investigate.

What’s the background of all that?

The AppStore description of the app also links to a Twitter account and the source code of the app on Github:

From these two links I basically spent hours reading, clicking, reading again – typical procrastination stuff (Procrastinators beware if you are even near Wikipedia articles…). But I learned a lot ;) Back to topic: The following links all are relevant to the mobile efforts of Wikipedia:

While reading these pages, I noticed information about two different iOS apps: One is based on Rhodes, one on Phonegap. It turns out the Phonegap version for iOS is quite new and the old one is to be retired and phased out:

So we have several projects and initiatives in the mobile space of Wikipedia:

Not too bad. Of course the articles in the wiki are quite… organically grown and sometimes hard to differentiate and classify. But I think that’s the case most of the time when volunteers and professionals work together.

The funny stuff: code

Now I have an overview, so let’s get back to the funny stuff: code.

As I have never used git before, I spend some time installing all the tools and learning how to use them. After that I can finally checkout the repository on Github. While I do this, I notice that the isn’t as pretty as all the readmes of the other Github projects I know. So that’s the first thing I decide to fix. 1 hours, lots of reading and 3 minutes of ‚coding‘ and a pull request later, it is done. My commit gets integrated by reedy a few minutes later. I’m in.

But now to the real code. The folder structure of the repository isn’t very clear. There are lot’s of confusing files in the root that don’t really belong there in a multi platform project, several folders that also don’t make sense to me or I can’t identify. Again, this seems to have grown over time. This is definitely something that could and should be fixed.

In /assets/www I find something that looks like the html application. Loooots of Javascript, jQuery and Zepto *confused. Anyway, using –disable-web-security I can open the Phonegap app in Chrome and even get it working! Still, several ‚file not found‘ as non-existant files are requested. But here it becomes quite clear, that the app itself is no bad in itself. It works, the code is more or less structured, you can see what the developer was thinking. Normally that’s a good thing. So as to not fish around without all information, I conclude my little poking session for today.


After getting this short glimpse into Wikipedia Mobile I think that the code isn’t the first problem to fix. First it needs some love in the Documentation and Organization of the code. So that’s where I will start. Let’s see what I can do.

PS: Well, I installed the app on my old iPod 3 (iOS 4.2.1) and tried to use it – completely unuseable. Maybe we should start with the code after all.

Kurze Analyse von Forge of Empires

Published 2012-03-29, 15:30

InnoGames hat mit Forge of Empires ein neues Browser-Aufbaustrategie-Spiel veröffentlicht. Logischerweise habe ich mir das ein wenig genauer angeschaut:



Performance-Optimierung am Beispiel:

Published 2012-03-22, 20:07

Ich habe mich ein wenig mit Performance Optimierung von Webseiten beschäftigt. In den nächsten Tagen und Wochen werde ich einige Beiträge dazu veröffentlichen. Den Anfang macht diese Beschreibung des Optimierungsvorgangs von

Beispielseiten für Optimierung


Erste Beobachtungen und Auswertung


Anwendbare Regeln aus High Performance Website Sites:

Rule 1 – Make Fewer HTTP Requests

Folgende Bilder können zusammengefasst werden:



Rule 3 – Add an Expires Header

Mit W3 Total Cache lässt sich sich das wunderbar erschlagen.


Rule 6 – Put Scripts at the Bottom

Das Analytics-Script ist zwar schon ganz unten, aber noch das alte synchrone. Also mal das neue besorgen und einbauen.


Rule 10 – Minify JavaScript (+ HTML + CSS)

Javascript gibt es keines, aber für Minify von HTML und CSS kann einfach W3 Total Cache konfiguriert werden, fertig.


Dann zum Abschluss noch ein bisschen serverseitiges Caching um DB-Anfragen und so weiter zu minimieren mit W3 Total Cache.


Tadaa, schnell.

Anwendungen und Tools zum Monitoring und Graphing von Serverdaten (Load, Memory, Traffic)

Published 2011-07-31, 18:19



Ergänzungen willkommen.

MySQL: temporäre Tabellen

Published 2009-06-23, 23:57

Große Queries, die sowieso per ‚Using temporary‘ anzeigen, dass im Hintergrund eine temporäre Tabelle erstellt wird, lassen sich oft wunderbar zwei- oder dreiteilen indem man erst eine temporäre Tabelle erstellt und dort nun dann die Abfragen ausführt. Besonders effektiv ist das, wenn Teil 1 des Queries die Anzahl der zu betrachtenden Zeilen stark einschränkt, Teil 2 dann jedoch nochmal heftig sortieren muss.

MySQL: Delete a subset in a table quickly

Published 2009-06-21, 14:04

Heute mal wieder über einen netten MySQL-Hack gestolpert:

The trick is, that INNER JOIN will ’shrink‘ the LargeTable down to the size of the TemporarySmallTable and the delete will operate on that smaller set only, since USING will reference to the joined table.

Mehr davon bitte…

File-Encoding erkennen

Published 2008-09-07, 20:00

Mein Held für heute: Mindprod mit seinem Encoding Recogniser. Applet kurz laden lassen, Datei auswählen und einfach Encodings durchprobieren. Funktioniert wunderbar.

MySQL: The table ‚foo‘ is full

Published 2008-03-31, 14:14

Ich muss zugeben, ich war erstmal ziemlich platt. Aber, es gibt ja zum Glück Erklärungen und (mutmaßliche) Lösungen:

Das von Jeremy Zawodny vorgeschlagene

alter table foo max_rows = 200000000000 avg_row_length = 50;

funktioniert auch wunderbar. Nun passen nochmal ein paar Gigabyte rein.

28 queries. 0,209 seconds.