I am new in Laravel , I want have a Comment Form and anybody can fill it , and the iput data will be inserted in database after a validating :
<?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') ;
}
}
now I want to be sure that nobody will not damage my site ! I want to save data completely safe ! I dont know is it necessary to sanitize form input ? if your answer is yes , How should I do it ?
I have seen this 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);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire