public function createUsersWithFriends($count) { $ids = []; for ($i = 1; $i <= $count; $i++) { $user = User::create(['login' => 'login_' . $i, 'password' => 'password_' . $i, 'email' => 'email_' . $i . '@example.com']); $ids[$i] = $user->id; for ($j = 1; $j < $i; $j++) { $friend = Friend::create(['personId' => $user->id, 'friendId' => $ids[$j]]); } } }
<?php require_once "../initialize.php"; if (isset($_GET['touserid'])) { $touserid = $_GET['touserid']; $friendship = new Friend(); $friendship->userid = $session->user_id; $friendship->touserid = $touserid; $friendship->create(); $notification = new Notification(); $notification->fromuserid = $session->user_id; $notification->touserid = $touserid; $notification->itemid = $friendship->id; $notification->itemtype = "friend"; $notification->create(); echo "success"; } else { echo "error"; }