Support the ongoing development of Laravel.io →
Database Eloquent Architecture

Hi,

I have the following situation:

I have the tables: actions action_access_ids

It's a one-to-many-relationship. One action can have many action_triggers.

Now I get the access_ids this way:

$action = Action::with('access_ids')->find(1);

Then, I can access all of the access_ids like this:

$action->access_ids[0]->value // first $action->access_ids[1]->value // second $action->access_ids[2]->value // third

But this way I don't know which access_id I'm selecting, because I only have an array with keys starting from 0. But every access_id has a name attribute to identify it.

Is something like this possible?:

$action->access_ids->get('nameOfAccess_id');

This method get() would loop through the access_ids and return the value of access_id with the name given. If this would be possible, where should I place this method in my Code?

Thank you in advance

d3mueller

Last updated 3 years ago.
0

Got it. Just added a method to the Collection Class :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

d3mueller d3mueller Joined 29 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.