I have two tables in the database, this is users and users_progress

users contains a field (name and etc), and users_progress contains a field (level and etc).

As planned, one user can have one level, i.e. it turns out the relationship one-to-one.


How to add data to the database using RedBeanPHP?

This is how I did for the tests table. But she has one-to-many relationship.

$user = R::dispense('users');
    $user->name = $data['name'];
    $user->surname = $data['surname'];
    $user->login = $data['login'];
    $user->email = $data['email'];
    $user->password = password_hash($data['password'], PASSWORD_DEFAULT);
    $user->start_date = date("Y-m-d H:i:s");

    // tests
    $test = R::dispense('tests');
    $test->name = 'base';
    $test->progress = false;
    $test->result = null;

    $user->ownTestList[] = $test;
    R::store($user);

0 Answers