public function run() { for ($x = 1; $x <= 25; $x++) { $user = User::find(rand(1, 5)); $f_user = User::find(rand(6, 10)); Follow::create(['user_id' => $user->id, 'following_user_id' => $f_user->id]); } }
public function run() { $faker = Faker::create(); $userIds = User::lists('id'); $groupIds = Group::lists('id'); foreach (range(1, 200) as $index) { Follow::create(['user_id' => $faker->randomElement($userIds), 'group_id' => $faker->randomElement($groupIds)]); } }
/** * Follows a user. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $user = User::where('username', $request->username)->first(); if (!$user) { return response()->json(['success' => false, 'message' => "No such user in our DB"]); } if (!$user->followable) { return response()->json(['success' => false, 'message' => "You cannot follow this user"]); } return response()->json(['success' => true, 'message' => "Successfully followed", 'like' => Follow::create(['user_id' => User::getCurrentUserId(), 'follow_id' => $user->id])]); }