Laravel 5 如何在inputdata进入数据库之前添加加密任务?
我制作了一个联系人表单,所有的输入数据都进入MySQL数据库。 保存后,它会自动向客户和我回复电子邮件。 这个很好用。下一步是对其进行加密 我必须将加密任务放在何处以及如何放置 我就这么做了Laravel 5 如何在inputdata进入数据库之前添加加密任务?,laravel-5,Laravel 5,我制作了一个联系人表单,所有的输入数据都进入MySQL数据库。 保存后,它会自动向客户和我回复电子邮件。 这个很好用。下一步是对其进行加密 我必须将加密任务放在何处以及如何放置 我就这么做了 php artisan密钥:生成 及 我可以看到加密数据 这是我的代码输入日期 Contact::create($request->all()) 我想知道如何解密和显示所有数据 php(我现在修复了两次) } 现在我犯了这个错误 htmlspecialchars() expects parameter 1
php artisan密钥:生成
及
我可以看到加密数据
这是我的代码输入日期
Contact::create($request->all())代码>
我想知道如何解密和显示所有数据
php(我现在修复了两次)
}
现在我犯了这个错误
htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp\php\041951257234\resources\views\contacts\confirm.blade.php)
可能是Hi Jonas的复制品。谢谢你的评论。对不起,我还是不明白。我可以加密每个数据中的一个并查看它。但我不知道如何在Contact::create($request->all())之前一次性写入所有数据;对不起,我不明白你的问题。您是否使用链接答案中的代码来调整您的联系人
型号?您所说的“加密”是什么意思。我假设您在保存到数据库时尝试加密数据。为此,你可以使用@JonasStaudenmeir在评论中提到的特质。它将在存储数据时加密数据,并在从数据库获取数据时解密数据。仅供参考:一旦加密数据库中的数据,就不能使用where子句查询它。因此,您必须使用收集方法获取所有数据并进行筛选。因此考虑使用数据库级加密()。
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
use EncryptsAttributes;
protected $fillable = [
'type',
'name',
'email',
'gender',
'body'
];
use EncryptsAttributes;
protected $encrypts = [
'type',
'name',
'email',
'gender',
'body'
];
static $types = [
'1',
'2',
'3',
'4'
];
}
<tr>
<th>name</th>
<td>{{ $contact->name }}
(This isn't encrypt)
<br>
{{ $contact->name = \Crypt::encrypt($contact->name) }}
(I this this before I asked here. I can see name encrypeted)
</td>
</tr>
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
{!! Form::label('name', 'YOUR NAME:', ['class' => 'col-sm-2 control-label']) !!}
<div class="col-sm-10">
{!! Form::text('name', null, ['class' => 'form-control']) !!}
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
</div>
foreach ($this->fillableFromArray($attributes) as $key => $value) {
$key = $this->removeTableFromKey($key);
// The developers may choose to place some attributes in the "fillable" array
// which means only those attributes may be set through mass assignment to
// the model, and all others will just get ignored for security reasons.
if ($this->isFillable($key)) {
$this->setAttribute($key, $value);
} elseif ($totallyGuarded) {
throw new MassAssignmentException(sprintf(
'Add [%s] to fillable property to allow mass assignment on [%s].',
$key, get_class($this)
));
}
}
return $this;
htmlspecialchars() expects parameter 1 to be string, array given (View: C:\xampp\php\041951257234\resources\views\contacts\confirm.blade.php)