Add global scope to limit template to current user

This commit is contained in:
Marcus Moore 2024-01-11 13:59:51 -08:00
parent 9c1bea00ad
commit d72970b5b6
No known key found for this signature in database

View file

@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Watson\Validating\ValidatingTrait;
@ -31,6 +32,14 @@ class ReportTemplate extends Model
'options' => 'array',
];
protected static function booted()
{
// Scope to current user
static::addGlobalScope('current_user', function (Builder $builder) {
$builder->where('user_id', auth()->id());
});
}
public function checkmarkValue(string $property): string
{
// Assuming we're using the null object pattern,