在我们使用的核心 php 中url_encode()
,url_decode()
我们可以在 laravel 4 中使用这个函数。如果可能,请告诉我如何。
<p> <a href="userregistrations/{{ $users-> id }}">{{ $users-> username }}</a>
我想编码$users->id
。这个 id 是什么过程或方法来编码这个 id 请帮助解码。
在我们使用的核心 php 中url_encode()
,url_decode()
我们可以在 laravel 4 中使用这个函数。如果可能,请告诉我如何。
<p> <a href="userregistrations/{{ $users-> id }}">{{ $users-> username }}</a>
我想编码$users->id
。这个 id 是什么过程或方法来编码这个 id 请帮助解码。
Laravel 提供了一个名为 encrypt 的辅助函数。所有加密值都使用 OpenSSL 和 AES-256-CBC 密码进行加密。下面是一个如何使用它的例子。
public function storeSecret(Request $request, $id)
{
$user = User::findOrFail($id);
$user->fill([
'secret' => encrypt($request->secret)
])->save();
}
加密值在加密期间通过序列化传递,这允许对对象和数组进行加密。因此,接收加密值的非 PHP 客户端将需要反序列化数据。如果你想在不序列化的情况下加密和解密值,你可以使用Crypt门面的encryptString和decryptString方法:
use Illuminate\Support\Facades\Crypt;
$encrypted = Crypt::encryptString('Hello world.');
$decrypted = Crypt::decryptString($encrypted);
您可以使用解密助手解密值。如果无法正确解密该值,例如 MAC 无效,则会抛出 Illuminate\Contracts\Encryption\DecryptException:
use Illuminate\Contracts\Encryption\DecryptException;
try {
$decrypted = decrypt($encryptedValue);
} catch (DecryptException $e) {
//
}