Skip to content

Instantly share code, notes, and snippets.

@thiagovictorino
Last active April 12, 2021 23:46
Show Gist options
  • Save thiagovictorino/767d2a53cc5db7a188d0b64390b01a80 to your computer and use it in GitHub Desktop.
Save thiagovictorino/767d2a53cc5db7a188d0b64390b01a80 to your computer and use it in GitHub Desktop.
<?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',
];
}
}
<?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