Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrogehlen committed May 21, 2024
1 parent fa5bd0f commit c8a42c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/InteractsWithCompany.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ public function company(): BelongsTo
*/
public function applyCompany()
{
$company = company()->current();
$foreignKeyName = $this->company()->getForeignKeyName();

if (! $company) {
throw new CompanyCouldNotBeIdentifiedException();
}

if ($this->{$foreignKeyName} === null) {
$company = company()->current();

if (! $company) {
throw new CompanyCouldNotBeIdentifiedException();
}

$this->{$foreignKeyName} = $company->id;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Middleware/InitializeCompanyByRequestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public function handle($request, Closure $next)

protected function getPayload(Request $request): ?string
{
$tenant = null;
$company = null;
if (static::$header && $request->hasHeader(static::$header)) {
$tenant = $request->header(static::$header);
$company = $request->header(static::$header);
} elseif (static::$queryParameter && $request->has(static::$queryParameter)) {
$tenant = $request->get(static::$queryParameter);
$company = $request->get(static::$queryParameter);
}

return $tenant;
return $company;
}
}

0 comments on commit c8a42c3

Please sign in to comment.