mapper wip
This commit is contained in:
1 parent
16cc214db6
commit
d635ebe563
38 files changed
+98
-680
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Scopes\SportScope;
|
||||
use App\Models\Scopes\UserScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BettypeUser extends Model
|
||||
@@ -13,6 +15,12 @@ class BettypeUser extends Model
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new SportScope);
|
||||
static::addGlobalScope(new UserScope);
|
||||
}
|
||||
|
||||
public function multiline()
|
||||
{
|
||||
return $this->hasOne(MultilineSetting::class, 'id', 'multiline_setting_id');
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Scopes\SportScope;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Event extends Model
|
||||
@@ -23,6 +24,11 @@ class Event extends Model
|
||||
'away_id',
|
||||
];
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::addGlobalScope(new SportScope);
|
||||
}
|
||||
|
||||
public function sport()
|
||||
{
|
||||
return $this->belongsTo(Sport::class);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class SportScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
if (auth()->hasUser()) {
|
||||
$builder->where('sport_id', auth()->user()->sport_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Scopes;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Scope;
|
||||
|
||||
class UserScope implements Scope
|
||||
{
|
||||
/**
|
||||
* Apply the scope to a given Eloquent query builder.
|
||||
*/
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
if (auth()->hasUser()) {
|
||||
$builder->where('user_id', auth()->user()->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user