Giter Club home page Giter Club logo

Comments (6)

toitzi avatar toitzi commented on June 18, 2024 1

Oh i get it, you are not overwriting a column with your attribute function, but rather creating a new one, understood, thats why it worked for me and not for you.

Yes the problem probably happens here in the resolveUsers function as there the columns are read:

public function resolveUsers(Collection $ids): Collection
{
    if ($this->usersResolver) {
        return collect(($this->usersResolver)($ids));
    } elseif (class_exists(\App\Models\User::class)) {
        return \App\Models\User::whereKey($ids)->get(['id', 'name', 'email']);
    } elseif (class_exists(\App\User::class)) {
        return \App\User::whereKey($ids)->get(['id', 'name', 'email']);
    }

    return $ids->map(fn (string|int $id) => [
        'id' => $id,
        'name' => "User ID: {$id}",
    ]);
}

You probaly need to overwrite the user resolver as you do above..i thnik that is the recommended solution in this case. I'd tend to say this is not a bug but working as intended (out of the box with standard laravel installation, where the name field does exist on the users table afaik). But i guess only a maintainer can answer that for sure :)

from pulse.

pyr0hu avatar pyr0hu commented on June 18, 2024

@joostvanhoof isn't these kindof attributes deprecated? could you try with the new one with Attribute::make?

protected function name(): Attribute
{
    return Attribute::make(get: fn () => $this->first_name.' '.$this->last_name);
}

from pulse.

toitzi avatar toitzi commented on June 18, 2024

@joostvanhoof Do you have any special configuration / model? Because i tried what you did and it workes flawlessly, having a quick look at the pulse source it should also work for you

from pulse.

joostvanhoof avatar joostvanhoof commented on June 18, 2024

@pyr0hu I had no clue 😅. I tried using Attribute::make but it gives the same error.

@toitzi not that I can think of, I left the Pulse config as is, and not sure what else could be 'special' about my setup.

Edit:
Interestingly, this works, using the name attribute:

Pulse::users(function ($ids) {
  return User::findMany($ids)->map(fn ($user) => [
    'id' => $user->id,
    'name' => $user->name,
    'email' => $user->email,
    'avatar' => '',
  ]);
});

from pulse.

joostvanhoof avatar joostvanhoof commented on June 18, 2024

Sorry, reopening here as there does seem something related to Pulse.

I have a some custom Middleware with this:

public function handle(Request $request, Closure $next)
{
    if (! auth()->user()) {
        return $next($request);
    }

    if (! auth()->user()->last_active_at or auth()->user()->last_active_at->isPast()) {
        auth()->user()->last_active_at = now();
    }

    return $next($request);
}

and Flare indicates the error is in the part return $next($request); on the last line of that function, which makes me think that it's something else. This error only happens when visiting the Pulse dashboard.

This is the error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'field list'
SELECT `id`, `name`, `email` FROM `users` WHERE `users`.`id` IN (1)

Now when I add

Pulse::users(function ($ids) {
  return User::findMany($ids)->map(fn ($user) => [
    'id' => $user->id,
    'name' => $user->name,
    'email' => $user->email,
    'avatar' => '',
  ]);
});

in AppServiceProvider, the error disappears.

from pulse.

joostvanhoof avatar joostvanhoof commented on June 18, 2024

Yes that makes sense, thanks for your help. I sometimes struggle with the stack trace not actually pointing to where the query happens. Will close this issue.

from pulse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.