Sunday, April 1, 2018

I am trying to create Edit user page but it returns "User not Found" - development

I am trying to create Edit user page but it returns "User not Found"

I am trying to create Edit user page but it returns “User not Found”. Here is my Edit UserController:

public function edit(Request $request, $id = null) {

    if($request->isMethod("GET")) {
        $user = User::find($id);
        if(is_null($user)) {
            return redirect()->back()->with("error", "User Not Found");
        }
        return view("admin.users.edit", ["user" => $user]);
    }

    elseif ($request->isMethod("POST")) {
        // remove me after test from
        $user = User::find($request->id);
        if(is_null($user)) {
            return redirect()->back()->with("error", "User not found");
        } // remove me after test to

        $this->validate($request, [
            "id" => "required",
            "name" => "required|string|min:3",

            // Will focus on Auth::User()
            // "email" => ["required", Rule::unique("users")->ignore(Auth::id())],
            // "phone" => ["required", Rule::unique("users")->ignore(Auth::id())]

            // Will focus on selected User
            "email" => ["required", Rule::unique("users")->ignore($user->id)],
            "phone" => ["required", Rule::unique("users")->ignore($user->id)]

        ]);

        // $user = User::find($request->id);
        $user->name = $request->name;
        $user->email = $request->email;
        $user->phone = $request->phone;
        $user->save();

        return redirect()->back()->with("status", "User Information was Updated Successfully");

    }

    else {
        return redirect()->back()->with("error", "Invalid Request");
    }
}

Please help me with the solution to this, Thanks



from Laravel Questions and Answers https://laravelquestions.com/php/i-am-trying-to-create-edit-user-page-but-it-returns-user-not-found/
via Lzo Media

No comments:

Post a Comment