Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

mohsin-shaikh/expense-tracker

31 stars
2 code files
View mohsin-shaikh/expense-tracker on GitHub

app/Scopes/UserVisibilityScope.php

Open in GitHub
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Support\Facades\Auth;
 
final class UserVisibilityScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
$builder->where('user_id', Auth::id());
}
}

app/Models/Category.php

Open in GitHub
use App\Scopes\UserVisibilityScope;
use Illuminate\Database\Eloquent\Model;
 
final class Category extends Model
{
//
protected static function booted(): void
{
static::addGlobalScope(new UserVisibilityScope());
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.