如何在inputdata进入dastabase之前添加加密任务?

时间:2018-04-21 12:55:53

标签: laravel-5

我建立了联系表格,所有输入数据都发送到MySQL数据库。 当它被保存时,它会自动向客户和我回复电子邮件。 这很好用。下一步是加密。

我在哪里必须加密加密任务?如何?

我刚刚做了

php artisan key:generate

    {{ $contact->name = \Crypt::encrypt($contact->name) }}

我可以看到加密数据。

这是我的代码输入日期去数据库

Contact::create($request->all());

我想知道如何解密和显示所有数据。

Contact.php(我现在修了两次)

<?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'
    ];



}

这是我的confirm.blade.php 为了检查我想看到加密数据

                        <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>

这是index.blade.php文件的名称部分

   <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>

现在我收到了这个错误  Illuminate \ Database \ Eloquent \ MassAssignmentException 将[_token]添加到可填充属性以允许在[App \ Contact]上进行批量分配。

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)

0 个答案:

没有答案