You can use pluck method, $groups = Post::inCategory(1)->with(‘user’,’user.group’)->get()->pluck(‘user.group’)->all()
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 […]
Deploying A Secure Public Docker Registry with Nginx and Traefik
These posts are primarily intended for a technical audience who are trying to deploy a Docker setup on a minimal budget, and for those who typically do not have the luxury of a large enterprise setup — it is ideal for someone who is setting up their own development environment […]
Laravel — accessor doesn’t work when collection returned as JSON
So, in collection returned as JSON, no accessor/mutator exist. Make a loop to call all your needed accessor/mutator is waaay too fat, but Laravel come with a built-in solution In your model Announcement.php, you just have to specifies the accessors/mutators that will always be appended on your requests. protected $appends […]