New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nova Relationship Count Field Package #31

Open
dillingham opened this Issue Sep 10, 2018 · 3 comments

Comments

Projects
None yet
5 participants
@dillingham
Collaborator

dillingham commented Sep 10, 2018

Package that provide count aggregate column for index view. Assuming a user / post scenario, the users index would have a "11 Posts" column provided a Count::make('App\Post'); within user resource fields()
Seems to be the purpose of lenses, just thought an option on main index would be handy.

ID Name Posts
1 Brian 11 posts
2 Sarah 5 posts
public function fields()
{
        return [
            Count:make('App\Post')
        ];
}

@dillingham dillingham changed the title from Nova Relationship Column Count Package to Nova Relationship Count Field Package Sep 10, 2018

@Kristories

This comment has been minimized.

Kristories commented Sep 27, 2018

Good idea. Clue :

Text::make('Total', function () {
    return $this->relation()->count();
}),
@MarceauKa

This comment has been minimized.

MarceauKa commented Oct 1, 2018

This is my solution.

On my Nova resource:

public function fields()
{
    Number::make('Posts count', function () {
        return $this->posts_count;
    })->onlyOnIndex(),
}

public static function indexQuery(NovaRequest $request, $query)
{
    return parent::indexQuery($request, $query)
        ->withCount('posts');
}
@nsaumini

This comment has been minimized.

nsaumini commented Nov 15, 2018

Just for fun & learning I have built the package. https://novapackages.com/packages/saumini/count

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment