I have a matrix that contains a block with a category field. I want to loop over the matrix models, in PHP, to get data. Here's what I have so far:
foreach ($user->networksMatrix as $key => $networkLink)
{
$netArr[$networkLink->id]["fields"]["networktype"] = $networkLink->networktype;
$netArr[$networkLink->id]["fields"]["networkUrl"] = $networkLink->networkUrl;
}
networktype is a category field. How do I get the get the ID of the category a user selected?
Thanks!
UPDATE
I discovered that the following works:
foreach ($user->networksMatrix as $key => $networkLink)
{
$netArr[$networkLink->id]["fields"]["networktype"] = $networkLink->networktype->ids()[0];
$netArr[$networkLink->id]["fields"]["networkUrl"] = $networkLink->networkUrl;
}
Since networktype is a categories field and that field is limited to 1 category I'll only ever get a single result from the method:
ids();
So... I just do this and I'm good:
$networkLink->networktype->ids()[0];