Validation unique sur la mise à jour Laravel
public function rules()
{
return [
'email' => 'required|email|unique:users,email,'.$this->user->id,
];
}
Fine Fly
public function rules()
{
return [
'email' => 'required|email|unique:users,email,'.$this->user->id,
];
}
use Illuminate\Support\Str;
public function yourFunction(){
$var = Str::random(32);
dd($var);
}
@if ($errors->any())
@foreach ($errors->all() as $error)
<div>{{$error}}</div>
@endforeach
@endif
/**
* Store a new blog post.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
// The blog post is valid...
}
$rules = [
'name' => 'required',
'email' => 'required|email',
'message' => 'required|max:250',
];
$customMessages = [
'required' => 'The :attribute field is required.'
];
$this->validate($request, $rules, $customMessages);
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreUserRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'username' => 'required|min:8',
'email'=>'required|email|unique:users,email,NULL,id,deleted_at,NULL'
];
}
}