pilat's avatar

pilat wrote a comment+100 XP

3mos ago

3:00 - "including import statements".. hmm, that didn't work in beta. Will definitely try it tomorrow!

pilat's avatar

pilat wrote a comment+100 XP

4mos ago

You say it's the simplest relationship, but how do you enforce it? What if I write the same user-id into two different profile records? In this regard, HasMany and its BelongsTo companion are simpler to implement, because they don't promise to much ;)

pilat's avatar

pilat wrote a reply+100 XP

4mos ago

with unique(), the first item it stumbled upon will remain. BUT, this is not common for all the methods. In keyBy(), for example, the last item will replace anything before

$coll = [
    ['tag' => 1, 'value' => 11],
    ['tag' => 1, 'value' => 12],
    ['tag' => 2, 'value' => 21],
    ['tag' => 2, 'value' => 22],
];

[
    'unique' => collect($coll)->unique('tag')->pluck('value')->all(),
    // BUT!
    'keyBy' => collect($coll)->keyBy('tag')->pluck('value')->all(),
];

// output:
[
    "unique" => [11, 21],
    "keyBy" => [12, 22],
  ]
pilat's avatar

pilat wrote a reply+100 XP

5mos ago

Just wanted to mention this:

Larastan shouts on me:

 Called 'Model::make()' which performs unnecessary work, use 'new Model()'.
         🪪  larastan.noModelMake

So, I consider that someone has investigated this topic and came to conclusion that it makes sense to use new Model() syntax.