Published in Laravel 5

Laravel 5: Encrypting Strings With encrypt

By John Koster

The encrypt helper function can be used to encrypt a given string value. The function resolves the configured "Illuminate\Contracts\Encryption\Encrypter" implementation from the Service Container and then calls the encrypt method on the Encrypter instance.

#Signature

The signature of the encrypt function is:

1function encrypt(
2 $value
3);

#Example Use

The following examples are all equivalent:

1use Illuminate\Support\Facades\Crypt;
2
3// Encrypt using the Crypt facade:
4Crypt::encrypt('Hello, Universe');
5
6// Encrypt using the encrypt helper:
7encrypt('Hello, Universe');
8
9// Retrieve an instance from the Service Container.
10app('encrypter')->encrypt('Hello, Universe');
11
12// Retrieve an instance from the Service Container.
13resolve('encrypter')->encrypt('Hello, Universe');