Removing eval from PHP function [closed]

As mentioned, there is absolutely no reason to use eval here. What you need to do is build up an array of values that you want to pass in, then decide if it needs to be a new user or an update.

public function alterUser()

    $name = $_POST['name']; //required field
    $contact = $_POST['contact']; //required field
    $password = $_POST['password']; //required field

    $values = [
        'name' => $name,
        'password' => Hash::make($password),
        'contacto' => $contact

    if (isset($_POST['email'])) {
        $values['email'] = $_POST['email'];

    if (isset($_POST['nif'])) {
        $values['nif'] = $_POST['nif'];

    if(!empty($_POST['id'])) {
    } else {
        DB::table('users')->where('id', $_POST['id'])->update($values);
    return redirect('/user');

Browse More Popular Posts

Leave a Comment