Laravel Encrypt Decrypt
Description
A web application built with Laravel that focuses on secure data management. The application utilizes encryption to ensure that sensitive information is securely stored within the database. It encrypts data before storing it, and decrypts it when retrieved, all handled in the model layer using Laravel's accessors and mutators.
Work Flow
Example on create new product
- User input data
- Data will pass to controller
- Controller will interact with related service for store data
- Service will store data using eloquent model (Product::create)
- In the model, setters are used to encrypt the data before it is stored in the database.
- Data will store to database in encrypted format
So, how to decrypt data?
As we know, the data is encrypted in the model before being stored in the database. Similarly, when retrieving the data, during the data retrieval with the model in the service, the model has an accessor to decrypt the columns when they are accessed.
So, the conclusion?
The encryption and decryption processes are handled in the model using accessors and mutators provided by Laravel. However, for the encryption option, the EncryptionService is used, which refers to the .env file for the encryption settings.
Example Available Data

