This commit is contained in:
Bozhidar 2024-05-13 00:10:56 +03:00
parent 5a9cd63159
commit 6b2263a8c9
3 changed files with 49 additions and 11 deletions

View file

@ -0,0 +1,38 @@
<?php
namespace Modules\Customer\App\Http\Middleware;
use Filament\Facades\Filament;
use Filament\Models\Contracts\FilamentUser;
use Illuminate\Auth\Middleware\Authenticate;
use Illuminate\Database\Eloquent\Model;
class CustomerAuthenticate extends Authenticate
{
/**
* @param array<string> $guards
*/
protected function authenticate($request, array $guards): void
{
$guard = Filament::auth();
if (! $guard->check()) {
$this->unauthenticated($request, $guards);
return;
}
$this->auth->shouldUse(Filament::getAuthGuard());
// /** @var Model $user */
// $user = $guard->user();
//
// $panel = Filament::getCurrentPanel();
}
protected function redirectTo($request): ?string
{
return Filament::getLoginUrl();
}
}

View file

@ -75,7 +75,7 @@ class CustomerPanelProvider extends PanelProvider
])
->authGuard('web_customer')
->authMiddleware([
Authenticate::class,
CustomerAuthenticate::class,
]);
}

View file

@ -37,16 +37,16 @@ class HostingSubscriptionBackup extends Model
'status' => BackupStatus::class,
];
// protected static function booted(): void
// {
// static::addGlobalScope('customer', function (Builder $query) {
// if (auth()->check() && auth()->guard()->name == 'web_customer') {
// $query->whereHas('hostingSubscription', function ($query) {
// $query->where('customer_id', auth()->user()->id);
// });
// }
// });
// }
protected static function booted(): void
{
static::addGlobalScope('customer', function (Builder $query) {
if (auth()->check() && auth()->guard()->name == 'web_customer') {
$query->whereHas('hostingSubscription', function ($query) {
$query->where('customer_id', auth()->user()->id);
});
}
});
}
public static function boot()
{
parent::boot();