Last active
April 12, 2021 23:46
-
-
Save thiagovictorino/767d2a53cc5db7a188d0b64390b01a80 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class UpdateUserRequest extends BaseRequest | |
{ | |
/** | |
* Determine if the user is authorized to make this request. | |
* | |
* @return bool | |
*/ | |
public function authorize(): bool | |
{ | |
return auth()->user()->isAdmin(); | |
} | |
/** | |
* Get the validation rules that apply to the request. | |
* | |
* @return array | |
*/ | |
public function rules(): array | |
{ | |
return [ | |
'first_name' => 'required', | |
'last_name' => 'required', | |
'address_name' => 'required', | |
]; | |
} | |
} |
This file contains hidden or 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 | |
class UserController | |
{ | |
public function update(UpdateUserRequest $request) | |
{ | |
$user = User::findOrFail($request->get('user_id')); | |
$user->active = $request->get('active', false); | |
$user->first_name = $request->get('first_name'); | |
$user->last_name = $request->get('last_name'); | |
$user->address = $request->get('address'); | |
$user->save(); | |
return redirect()->back(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment