我在Laravel是新的,我想有一個意見表和任何人都可以填滿它,並iput數據將在數據庫中的驗證之後插入:如何保存在數據庫中laravel 5.1安全的數據?
<?php
namespace App\Http\Controllers;
use App\comments;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class CommentController extends Controller
{
public function postCommentNew(Request $request)
{
$this->validate($request, [
'commenter' => 'required|max:255',
'email' => 'required|max:255',
'comment' => 'required',
'post_id' => 'required'
]);
comments::create($request->all());
return redirect()->back()->with('success' , 'Comment Submited') ;
}
}
現在我想,以確保沒有人會不損壞我的網站!我想保存數據完全安全!我不知道是否有必要清理表單輸入?如果你的答案是肯定的,我該怎麼做?
我已經看到了這here:
public function sanitize()
{
$input = $this->all();
if (preg_match("#https?://#", $input['url']) === 0) {
$input['url'] = 'http://'.$input['url'];
}
$input['name'] = filter_var($input['name'], FILTER_SANITIZE_STRING);
$input['description'] = filter_var($input['description'],
FILTER_SANITIZE_STRING);
$this->replace($input);
}
我我問一個消毒過濾器只爲數據庫中插入 –