Encrypting and decrypting data
When writing applications that deal with sensitive data, we may often want to encrypt any data that we store in our database. Laravel provides us with a solution to do just that.
Getting ready
For this recipe, we need a standard installation of Laravel, as well as a properly set-up and configured MySQL database.
How to do it...
This is how we'll complete the recipe using the following steps:
In the
app/config
directory, open theapp.php
file and make sure thekey
is empty'key' => '',
In the command line, go to the root of the application and generate a new key using the following command:
php artisan key:generate
Create a table in the database to hold our sensitive information using this following command:
CREATE TABLE accounts( id int(11) unsigned NOT NULL AUTO_INCREMENT, business varchar(255) DEFAULT NULL, total_revenue varchar(255) DEFAULT NULL, projected_revenue varchar(255) DEFAULT NULL, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET...