app/Http/Controllers/UserController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $request->validate([
            'name' => ['required','min:5','max:50'],
            'email'=> ['required','min:3'],
            'phone'=> ['required','min:10']
        ]);
        $user = User::find($id);
        if($request->hasFile('image')){
            $file_path = public_path('images/user_images/').$user->image;
            if($user->image != "" && file_exists($file_path))
            {
                 unlink($file_path);
            }
             $fileName = time().'.'.request()->image->getClientOriginalExtension();
             request()->image->move(public_path('images/user_images'), $fileName);
             $user->image =  $fileName;
         }
        $user->name = $request->name;
        $user->email = $request->email;
        $user->phone = $request->phone;
        $user->role = $request->role;
        $user->save();
        return redirect()->to("/usersListing")->with('success',"Update Successfully");
    }
public function update ( Request $ request , $ id ) { $ request -> validate ( [ 'name' => [ 'required' , 'min:5' , 'max:50' ] , 'email' => [ 'required' , 'min:3' ] , 'phone' => [ 'required' , 'min:10' ] ] ) ; $ user = User :: find ( $ id ) ; if ( $ request -> hasFile ( 'image' ) ) { $ file_path = public_path ( 'images/user_images/' ) . $ user -> image ; if ( $ user -> image != " " && file_exists ( $ file_path ) ) { unlink ( $ file_path ) ; } $ fileName = time ( ) . '.' . request ( ) -> image -> getClientOriginalExtension ( ) ; request ( ) -> image -> move ( public_path ( 'images/user_images' ) , $ fileName ) ; $ user -> image = $ fileName ; } $ user -> name = $ request -> name ; $ user -> email = $ request -> email ; $ user -> phone = $ request -> phone ; $ user -> role = $ request -> role ; $ user -> save ( ) ; return redirect ( ) -> to ( " /usersListing " ) -> with ( 'success' , " Update Successfully " ) ; }
Update the specified resource in storage.
Update the specified resource in storage .