-
Notifications
You must be signed in to change notification settings - Fork 673
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add request class to validate user input
- Loading branch information
1 parent
9fbcf8f
commit ea95540
Showing
2 changed files
with
59 additions
and
23 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Wave\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class ProfileUpdateRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get custom messages for validator errors. | ||
* | ||
* @return array | ||
*/ | ||
public function messages() | ||
{ | ||
return [ | ||
'avatar.base64image' => 'The avatar must be a valid image.' | ||
]; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required|string', | ||
'email' => 'sometimes|required|email|unique:users,email,' . Auth::user()->id, | ||
'username' => 'sometimes|required|unique:users,username,' . Auth::user()->id, | ||
'avatar' => 'nullable|base64image' | ||
]; | ||
} | ||
} |