Skip to content

Instantly share code, notes, and snippets.

@mrailton
Last active September 22, 2015 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrailton/22f6c5abc08a8c7d4337 to your computer and use it in GitHub Desktop.
Save mrailton/22f6c5abc08a8c7d4337 to your computer and use it in GitHub Desktop.
Update user validation
<?php
namespace App\Http\Requests;
use Illuminate\Support\Facades\Hash;
class UserUpdateRequest extends Request
{
/**
* 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',
'email' => 'unique:users,email,'.$this->id,
'password_confirm' => 'required_with:password|same:password'
];
}
public function userFillData()
{
if (empty($this->password)) {
$password = null;
} else {
$password = Hash::make($this->password);
}
return [
'name' => $this->name,
'email' => $this->email,
'password' => $password,
'enabled' => $this->enabled,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment