Replies: 4 comments 1 reply
-
Like I can solve it w/ getting the data as an array, splicing, then rehydrating, but seems a bit awkward. This is what I'm doing now: $raw = $this->stations->toArray();
array_splice($raw, $index, 1);
$this->stations = new DataCollection(Station::class, $raw); |
Beta Was this translation helpful? Give feedback.
-
Hi @edalzell, Do you have a complete code example where this is going wrong? Then I'll take a closer look, it's not completely clear for my what's going wrong. |
Beta Was this translation helpful? Give feedback.
-
Sure thing Ruben, thanks for looking in to this. I have a model, protected $casts = [
'scheduled_at' => 'datetime',
'stations' => DataCollection::class.':'.Station::class,
'type' => WorkoutType::class,
]; Station: class Station extends Data implements Wireable
{
use WireableData;
public function __construct(
#[Required, IntegerType]
public ?int $sets,
#[Required, StringType]
public ?string $title,
#[Required, DataCollectionOf(Exercise::class)]
public ?DataCollection $exercises
) {
}
}
[
[
"sets" => 2,
"title" => "Station 1",
"exercises" => [
[
"id" => "bc6acc17-b792-4991-a54c-82fba0057aae",
"activity" => "7x Quisquam deserunt sit ipsum.",
],
[
"id" => "ece742e4-1686-43bd-bc83-86aa0adb4f73",
"activity" => "5x Aut est aperiam vel amet.",
],
],
],
[
"sets" => 3,
"title" => "Station 2",
"exercises" => [
[
"id" => "bc6acc17-b792-4991-a54c-82fba0057aae",
"activity" => "7x Quisquam deserunt sit ipsum.",
],
[
"id" => "ece742e4-1686-43bd-bc83-86aa0adb4f73",
"activity" => "5x Aut est aperiam vel amet.",
],
],
],
] If I See how there's an index now I understand why that's happening but maybe there should be a |
Beta Was this translation helpful? Give feedback.
-
Hmmm I get what you're suggesting but this seems like correct behavior to me since it is how PHP works. As for the You could always implement a custom DataCollection, and add such a method over there. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Great package!
I'm storing a JSON array into a DB, and when I use
offsetUnset
it properly removes the item, but doesn't re-index so the stored JSON is wrong.Any advice?
Beta Was this translation helpful? Give feedback.
All reactions