lundi 25 février 2019

How new user when registered automatically follows a user in laravel

I want when user signup it follows a specific user automatically. How can i do this in laravel. Here is my code. Please help thanks in advance

public function signUp(RegisterUser $request)
{
    if($profile_picture = $request->hasFile('profile_picture')) {
        $profile_picture = time().'.'.$request->profile_picture->getClientOriginalExtension();
        $request->profile_picture->move(public_path('ProfileImages'), $profile_picture);
        $profile_picture = 'ProfileImages/'.$profile_picture;
    } else {
        $profile_picture = NULL;
    }

    $user = User::create([
        'firstname' => $request->input('firstname'),
        'lastname' => $request->input('lastname'),
        'email' => $request->input('email'),
        'password' => bcrypt($request->input('password')),
        'password_changed_at' => Carbon::now()->toDateTimeString(),
        'username' => $request->input('username'),
        'profile_picture' => $profile_picture,
        'email_verification_token' => str_random(50),
    ]);

    if (!$user) {
        return response()->json(['failed to create new user'], 500);
    }

    $token = JWTAuth::fromUser($user);

    $userDetail = $user->where('id', $user->id)->with(['posts', 'buckets','likes', 'followers', 'following'])->withCount('posts', 'buckets','likes', 'followers', 'following')->first();

    $this->verifyEmail($user);

    $id = 9;
    $userFollow = User::find($id);
    dd($userFollow);
    $user->follow($userFollow);

    // return response()->json(['message' => 'Please Check your email to verify your account Or Login to Kindmill']);
    return response()->json(['token' => $token, 'user' => $userDetail], 200);
}

Here in this way i can do but cannot work. Please help



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2H38CDh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire