コード例 #1
0
 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]);
     }
 }
コード例 #2
0
ファイル: DatabaseSeeder.php プロジェクト: Jemok/skoolspace
 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)]);
     }
 }
コード例 #3
0
 /**
  * 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])]);
 }