Download the PHP package andydefer/laravel-casts without Composer

On this page you can find all versions of the php package andydefer/laravel-casts. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-casts

Laravel Eloquent Casts

Advanced Eloquent casts for Laravel including Money and JSON handling

PHP Version Laravel Version


Installation

Prérequis


Casts disponibles

Cast Description Stockage DB Affichage
MoneyCast Montants monétaires Integer (centimes) Float (euros/dollars)
JsonCast Données structurées JSON string PHP array

MoneyCast

Le MoneyCast convertit automatiquement les montants monétaires entre les centimes (stockage en base de données) et les euros/dollars (affichage dans l'application).

Pourquoi ?

Stockez vos prix en centimes (entiers) pour éviter les problèmes de précision des nombres flottants en base de données.

Utilisation

Exemple

Gestion des arrondis

Valeurs négatives

Requêtes


JsonCast

Le JsonCast convertit automatiquement les chaînes JSON en tableaux PHP et vice-versa.

Pourquoi ?

Manipulez naturellement des données JSON en PHP sans avoir à gérer manuellement l'encodage/décodage.

Utilisation

Exemple

Conservation des JSON existants

Si vous stockez déjà une chaîne JSON valide, elle est préservée :

Gestion des erreurs

Les JSON invalides retournent null au lieu de planter :

Décodage non-tableau

Si un JSON décodé n'est pas un tableau, un tableau vide est retourné :


Installation dans un modèle existant

Migration avec MoneyCast

Migration avec JsonCast


Tests

Le package inclut une suite complète de tests unitaires.

Exécution des tests

Couverture des tests MoneyCast

Test Description
test_get_converts_cents_to_euros_with_two_decimals Conversion centimes → euros
test_get_rounds_cents_correctly Arrondi des centimes
test_get_handles_large_amounts Grands montants
test_get_handles_negative_amounts Valeurs négatives
test_get_returns_null_when_value_is_null Valeurs nulles
test_set_converts_euros_to_cents Conversion euros → centimes
test_set_rounds_cents_correctly Arrondi des euros
test_null_values_are_preserved_through_round_trip Préservation des nulls

Couverture des tests JsonCast

Test Description
test_get_returns_null_when_value_is_null Valeurs nulles
test_get_decodes_valid_json_string_to_array Décodage JSON valide
test_get_returns_null_when_json_string_is_invalid JSON invalide
test_set_converts_array_to_json_string Conversion tableau → JSON
test_set_throws_json_exception_for_non_encodable_values Valeurs non encodables

Exemples complets

E-commerce : Gestion des prix

Configuration utilisateur avancée

Inventaire avec attributs variables


Performance

Cast Opération Impact
MoneyCast Conversion int ↔ float Minime (opérations mathématiques simples)
JsonCast Encodage/décodage JSON Modéré (dépend de la taille des données)

API Reference

MoneyCast

Méthode Type Description
get(Model $model, string $key, mixed $value, array $attributes) ?float Convertit les centimes → euros
set(Model $model, string $key, mixed $value, array $attributes) ?int Convertit les euros → centimes

JsonCast

Méthode Type Description
get(Model $model, string $key, mixed $value, array $attributes) ?array JSON → tableau PHP
set(Model $model, string $key, mixed $value, array $attributes) ?string Tableau PHP → JSON

Limitations

MoneyCast

JsonCast


Contribuer

  1. Fork le repository
  2. Créer une branche (git checkout -b feature/amazing-feature)
  3. Commiter les changements (git commit -m 'feat: add amazing feature')
  4. Pusher (git push origin feature/amazing-feature)
  5. Ouvrir une Pull Request

Développement


Licence

MIT © Andy Defer


All versions of laravel-casts with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
laravel/framework Version ^12.0|^13.0|^14.0|^15.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package andydefer/laravel-casts contains the following files

Loading the files please wait ...