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

Hello,

I want to have rows which are based on a user, so for example if I do a find I would see MY rows, if Bob did he would see HIS rows.

Now the way I have been doing this is a combo of

->where('to_user_id', Sentinel::getUser()->id);

But I am not a fan of requiring Sentinel in my Repository and it requires doing some weird construct stuff in my Repository to accommodate testing.

Basically

public function __construct(Model $model, $userid) {
    if (empty($userid) { // Do something using sentinel to get the current user id
    } else { // Set the user id to what is passed
    }
}

So that I can use a different user id in my repository while testing.

Does anyone have any suggestions or ideas on how I could make this a bit easier to manage and test with and remove my dependency on Sentinel (or what ever user system) in my repository?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

dubcanada dubcanada Joined 13 Nov 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.