PHP : hotspot user delete?

Hi,
how hotspot user delete?
i can’t delete

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

$util = new RouterOS\Util($client = new RouterOS\Client('192.168.0.1', 'admin', 'password'));

$util->setMenu('/ip hotspot user remove [find name=77777777]');

?>

As the name suggests, setMenu() is only about the menu, not about the command.

There are separate methods for each command. In this case:

$util->setMenu('/ip hotspot user')->remove(RouterOS\Query::where('name', '77777777'));

(also, side note, the latest version is 1.0.0b6)

Thanks

i want to :

i add user. if user found this user update else add

New hotspot user add:

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';

if($mikrotikuserfound)
{
//update command? :(
}
else
{
//add hotspot user
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.0.1', 'admin', 'password'));

$util->setMenu('/ip hotspot user')->add(
    array(
        'name' => 'a',
        'password' => 'password1',
        'profile' => 'profile1'
    )
);
//add hotspot user
}

how do found?

For the update, set() is the command you’re looking for, and for the check, find(), which will be an empty string if the user is not found.

Also, move the unconditional parts above the check, f.e.

<?php
use PEAR2\Net\RouterOS;

require_once 'PEAR2_Net_RouterOS-1.0.0b5.phar';
$util = new RouterOS\Util($client = new RouterOS\Client('192.168.0.1', 'admin', 'password'));

$util->setMenu('/ip hotspot user');
$mikrotikuser = 'a';

$mikrotikuserfound = $util->find(RouterOS\Query::where('name', $mikrotikuser));
if($mikrotikuserfound) {
    $util->set(
        $mikrotikuserfound,
        array(
            'password' => 'password1',
            'profile' => 'profile1'
        )
    );
} else {
    $util->add(
        array(
            'name' => $mikrotikuser,
            'password' => 'password1',
            'profile' => 'profile1'
        )
    );
}

(on a related note, remove() can be given the ID from “find”, allowing you to check if an item exists before attempting to delete it)

thank you so much

i want as exactly :bulb: