Hi @jlrdw , thank you for having a look here.
It was simpler than I thought - just removing required from $this->validate(request(), lifted that validation error as you first pointed out. The html5 required has been added to the html select elements for added browser validation.
After thinking about it for a while I recognized this controller is not storing the roles/permissions it's using the html selects to check against known roles/permissions and if that clears then the roles/permissions are attached using eloquent in the backend.
Do you, or anyone else, see any security flaws in this approach?
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate(request(), [
'email' => 'string|email|max:255',
'companyrole' => 'string|min:3',
'companypermissions' => 'string|min:3',
]);
$roleExists = Role::roleExists(request('companyrole'));
$permissionExists = Permission::permissionExists(request('companypermissions'));
if ($roleExists === true && $permissionExists === true) {
$userExists = User::userExists(request('email'));
// dd($userExists);
if ($userExists) {
$companyHasAdministrator = Company::CompanyHasAdministratorRole(request('companyrole'));
// dd($companyHasAdministrator);
if ($companyHasAdministrator === false) {
// dd($userExists);
$role = Role::currentRole(request('companyrole'));
// dd($role);
$permission = Permission::currentPermission(request('companypermissions'));
$userExists->roles()->attach($role);
$role->givePermissionTo($permission);
flash('Thank you for adding roles and permissions.')->success();
return back();
} else {
flash('This company already has an administrator. Please select another role for that user.')->warning();
return back();
}
} else {
flash('No one with that email exists. Would you please invite them in the Invitations Center below? After they accept you may add their roles and permissions.')->warning();
return back();
}
} else {
flash('You have been reported to the FBI.')->warning();
return back();
}