avatar
Laravel
Переслано от канала
27.07.2025 23:35
???? ensure() ?? ???? Collection ?????? ??? ?????? ?? ??? ???? ?? ??? ????? ???????? ???? ?????? ?? ?????????? ????. ??? ???? ????? ????? ?? ??? ??? ????? ?? ?? ???? ???? ?? ??? ??????? ??? int? string ?? bool ???? ?? ??.

??? ??? ??? ?? ??????? ??? ??????? ????? ????? ?? Exception ?? ???? ? ?????? ????? ??? ?????.

??? ??????? ?????

????? ??????? ???? ??

??????? ?? ?????? ???? ???? ???? ?? ??? ???? ? ??????

?? ?????? ? ???? ??????? ??

???????? ?? ????? ????? ? ???????

????:
$numbers = collect([10, 20, 30]);

$numbers->ensure('int'); // ???? ??? ???? ????

??:
$products = collect([$product1, 'not a product']);

$products->ensure(Product::class); // ?? exception ??? ????

???? ensure() ?? ??? ???? ? ???? ???? ??????? ?? ??? ??? ??????? ???? ??????? ?? ???? ???? ?? ??? ??????? ? ???? ?????????? ????.

@GoldenCodeir

#Laravel
(??????? ? ????? ??? ???? ????)
https://x.com/MrPunyapal/status/1947691817694335268?s=1
X (formerly Twitter)
Punyapal Shah | Laravel Artisan | PHP Developer (@MrPunyapal) on X
Laravel's Collection::ensure() ? Validate the type of every item in your collection — or get an exception ? Supports class names and primitive types like 'int', 'string', 'bool', etc. Super handy for safe mapping ?
18 1.6K

Обсуждение 0

Обсуждение не доступно в веб-версии. Чтобы написать комментарий, перейдите в приложение Telegram.

Обсудить в Telegram