Laravel: Has Many Through Pivot… elegantly

Laravel Relationships pretty much cover everything that a model can access. We have One-To-One, One-To-Many, Many to Many, Polymorphic relations, etc. But there is one relation that is not covered because it’s very niche: Has Many Through Pivot. Has Many Through Pivot means: accessing a distant “one to many” relationship […]

Windows and Unix command line equivalents

This page was created on Sat Oct 09 2010 and last changed on Thu Mar 28 2019. This lists similar commands between Windows and Unix command lines. To get help on a Windows command, use the /? option, for example date /?. Windows command    Unix command    Notes arp    arp    assign    […]

Laravel 5 Eloquent appending relationships to JSON on multiple levels

If somebody is still interested in a solution for this: Laravel 5.5 introduced Api Resources which is a great way to organize the api responses. Just don’t include any relationships on your model and append them on the resource. namespace App\Http\Resources; use Illuminate\Http\Resources\Json\Resource; class UserResource extends Resource { public function […]

7 хитростей работы с моделями в Laravel

Когда впервые начинал работать с Laravel, я чувствовал, что есть много вещей, которые можно сделать лучше, когда доходило до реализации моделей. После погружения в класс Eloquent Model я обнаружил некоторые интересные вещи, значительно облегчающие работу с моделями. В этой статье я дам вам семь советов, которые должен знать каждый, использующий […]

PHP: How to use array_filter() to filter array keys

PHP 5.6 introduced a third parameter to array_filter(), flag, that you can set to ARRAY_FILTER_USE_KEY to filter by key instead of value: $my_array = [‘foo’ => 1, ‘hello’ => ‘world’]; $allowed = [‘foo’, ‘bar’]; $filtered = array_filter( $my_array, function ($key) use ($allowed) { return in_array($key, $allowed); }, ARRAY_FILTER_USE_KEY ); Clearly […]

Laravel : Saving a belongsToMany relationship

Considering your tables are users, signatures and user_signatures Define the relation in model: User.php class User extends Model { public function signatures() { return $this->belongsToMany(‘\App\Signature’, ‘user_signatures’); } } Define the inverse of the relation in model: Signature.php class Signature extends Model { public function users() { return $this->belongsToMany(‘\App\User’, ‘user_signatures’); } […]

Private Docker Registry

Creating a Registry and TLS-encrypt with Traefik (Let’s Encrypt) and use Native Basic Auth Authentication We are configured with Traefik as a proxy with TLS so we can use Native basic auth Perhaps it would be possible to use Traefik to work as an Authentication Proxy, but alas I have […]