I have a Table Role
with the attributes id
and Role
.
I do some of the roles softdelete
.
Now, when I want to create a new role I have the following rules:
public function rules() {
return [
'role' => 'required|unique:role,role|alpha'
];
}
If the role does not exist, it will create it.
public function store(NewRoleRequest $request) {
$request['role'] = strtoupper($request->input('role'));
$this->roleRepo->create($request->all());
return redirect()
->route('role.create')
->with('create-success', 'Role agregado correctamente.');
}
What I can not do is that if the Role already exists in the database but it has softDelete
, it will restore it. That is, when you go to the method store
and check the rules, see some form if that role is already that I want to create as sofdelete
, if it is the restore()
, but believe it.
Also if the attribute is unique, it automatically redirects me to the view again.