Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mahendran-balaji/encryption-and-decryption-using-laravel-10
Laravel Encrypt and Decrypt from Model
https://github.com/mahendran-balaji/encryption-and-decryption-using-laravel-10
encryption-decryption laravel-framework laravel10
Last synced: about 6 hours ago
JSON representation
Laravel Encrypt and Decrypt from Model
- Host: GitHub
- URL: https://github.com/mahendran-balaji/encryption-and-decryption-using-laravel-10
- Owner: Mahendran-Balaji
- Created: 2023-11-26T15:00:17.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2023-11-27T17:41:54.000Z (12 months ago)
- Last Synced: 2023-11-27T21:37:02.666Z (12 months ago)
- Topics: encryption-decryption, laravel-framework, laravel10
- Language: PHP
- Homepage:
- Size: 63.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Encryption and Decryption in Laravel 10
Laravel can encrypt it in Eloquent Models by simply casting it as encrypted.
We don't want our user sensitive information (This example used Bank Account Number) stored in plain text in our database, so encryption is a great way to protect it.
## Setup Encrypt and Decrypt in Model
In our model, we need to add the protected $casts property and the column we want to encrypt. In our case, it is bank_account_number:
```php
protected $casts = [
'bank_account_number' => 'encrypted',
];
```
Now, whenever you save the Bank Account Number on your user model - it will be encrypted, and on retrieval, it will get decrypted.## Warning
- The encryption algorithm mentioned above is based on your application's APP_KEY value.So you must keep your APP_KEY safe.
- If you change your APP_KEY - all your encrypted data will be lost. because this key is used for the encryption/decryption.## DO NOT RUN key:generate ON PRODUCTION SERVER.