3

In core php we use url_encode() and url_decode() so like this function we can use in laravel 4. If that's possible, please tell me how.

<p> <a href="userregistrations/{{ $users-> id }}">{{ $users-> username }}</a>

I want to encode $users->id. This id what is process or method to encode this id please help in decode as well.

shaedrich
  • 5,457
  • 3
  • 26
  • 42
user3825129
  • 501
  • 2
  • 5
  • 10
  • 1
    I don't know about laravel , but the code there seems to be parsed by a template engine . Maybe you should encode before you pass it to the engine , but i think that the template engine takes care of encoding (at least it should, otherwise you should use php as a template engine). – Tudor Jul 14 '14 at 10:37
  • Try `{{{ $users->id }}}` – sybear Jul 14 '14 at 11:02

1 Answers1

1

Laravel provides a helper function called encrypt. All encrypted values are encrypted using OpenSSL and the AES-256-CBC cipher. Below is an example how to use this.

public function storeSecret(Request $request, $id)
    {
        $user = User::findOrFail($id);

        $user->fill([
            'secret' => encrypt($request->secret)
        ])->save();
    }

Encrypted values are passed through serialize during encryption, which allows for encryption of objects and arrays. Thus, non-PHP clients receiving encrypted values will need to unserialize the data. If you would like to encrypt and decrypt values without serialization, you may use the encryptString and decryptString methods of the Crypt facade:

use Illuminate\Support\Facades\Crypt;

$encrypted = Crypt::encryptString('Hello world.');

$decrypted = Crypt::decryptString($encrypted);

You may decrypt values using the decrypt helper. If the value can not be properly decrypted, such as when the MAC is invalid, an Illuminate\Contracts\Encryption\DecryptException will be thrown:

use Illuminate\Contracts\Encryption\DecryptException;

try {
    $decrypted = decrypt($encryptedValue);
} catch (DecryptException $e) {
    //
}

Reference: https://laravel.com/docs/5.4/encryption

Muzammil Baloch
  • 176
  • 3
  • 14