Skip to content

Commit

Permalink
Added Laravel 10 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Jun 20, 2024
1 parent 4091d74 commit c08eccf
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Middlewares/LocalizationByModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ public function __construct(

protected function detect(Request $request): bool|float|int|string|null
{
if ($this->user($request)?->hasAttribute($this->attribute())) {
return $this->user($request)->getAttribute($this->attribute());
if ($this->has($user = $this->user($request))) {
return $user->getAttribute($this->attribute());
}

return null;
}

protected function has(?Model $user): bool
{
return $user && $this->hasAttribute($user);
}

protected function user(Request $request): ?Model
{
return $request->user($this->guard);
Expand All @@ -31,4 +36,13 @@ protected function attribute(): string
{
return $this->names()->column;
}

protected function hasAttribute(Model $user): bool
{
if (method_exists($user, 'hasAttribute')) {
return $user->hasAttribute($this->attribute());
}

return array_key_exists($this->attribute(), $user->getAttributes());
}
}

0 comments on commit c08eccf

Please sign in to comment.