What is the best way to limit the returned entries for a tableBuilder

edster - 3 weeks ago

I have a table builder for a stream called access. This stream has a user relation to it.

When you load up the table builder, I only want to return those access entries for that user to show up.

What is the best way to do that? Keep in mind I have other table builders that will need different type of content limitations done, so looking at the best overall implementation strategy for things like this.

Thanks!

Answer

- 3 weeks ago

Suggestion from failcookie

/**
     * Fired just before querying
     * for table entries.
     */
    public function onQuerying(Builder $query, Request $request)
    {
        $query->where('user_id', $request->route()->parameter('userid'));
    }

edster - 3 weeks ago

Suggestion from failcookie

/**
     * Fired just before querying
     * for table entries.
     */
    public function onQuerying(Builder $query, Request $request)
    {
        $query->where('user_id', $request->route()->parameter('userid'));
    }

ryanthompson - 3 weeks ago

Yep the onQuerying is the best spot to do that - then set data on your table you'll need in there accordingly.

ryanthompson - 3 weeks ago

I add setters/getters and an attribute sometimes for stuff like this just for an API doc'd paper trail.

edster - 3 weeks ago

Awesome thanks guys!