Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
get the auth users metadata fields
  • is there any way to get the metadata fields of the users (not only the logged in) from Auth?
  • Ormauth or Simpleauth?

    In case of Ormauth:

    // get the meta data for user 1:
    if ($user =  \Model\Auth_User::find(1, array('related' => 'metadata')))
    {
        $metatdata = \Arr::pluck($user->metadata, 'key', 'value');
    }
    else
    {
        // user not found
    }

  • Thanks a lot but i alrready did like this:

    $users = \Model\Auth_User::query()->get();

    foreach($users as $user){

      echo $user->the_metadata_field;

    }
  • HarroHarro
    Accepted Answer
    Ok, I misunderstood you then.

    I though you wanted all meta fields of a single user, not the same field from all users.

    Since you need the metadata for each user, include it in the query. You are lazy loading the data, which means it will run a query to get the meta data for every user. With 1000 users, your code runs 1001 queries. Better use

    $users = \Model\Auth_User::query()->related('metadata')->get();

    which will run 1 query.
  • It's always handy to have the profiler active when you develop your application, you can easily see the effect a code change has on the performance, the database I/O, the memory usage, etc.
  • thanks for the suggestion its a better way

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion