generated from IBEC-BOX/admin-kit-package-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace AdminKit\Localizations\UI\API\Data; | ||
|
||
use AdminKit\Localizations\Models\Localization; | ||
use Spatie\LaravelData\Data; | ||
|
||
class LocalizationData extends Data | ||
{ | ||
public function __construct( | ||
public string $key, | ||
public array|string $content, | ||
) { | ||
} | ||
|
||
public static function fromModel(Localization $localization): LocalizationData | ||
{ | ||
$content = $localization->getTranslations('content'); | ||
|
||
if ($locale = request('locale')) { | ||
$content = $content[$locale] ?? $content; | ||
} | ||
|
||
return new self( | ||
key: $localization->key, | ||
Check failure on line 25 in src/UI/API/Data/LocalizationData.php GitHub Actions / phpstan
|
||
content: $content, | ||
); | ||
} | ||
} |