Last active
September 22, 2015 09:01
Update user validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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