app/Http/Controllers/landingpage/ProfileController.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)
    {
        $user = User::query()->where('id', $id)->first();
        $request->validate([
            "image" => ['image',  "mimes:jpeg,png,jpg,svg", "max:2048", "nullable"],
            "username" => ['required', Rule::unique('users')->ignore($user->id)],
            'email' => ['email:dns', " required", Rule::unique('users')->ignore($user->id)],
        ], [
            "image.image" => "file must be image"
        ]);
        if ($request->hasFile('image')) {
            $imageName = time() . '-' . $user->username . "." . $request->file('image')->extension();
            $request->file('image')->move(public_path('assets/img/profile/' . $user->email), $imageName);
            $data =  [
                "image" => $imageName,
                "username" => $request->post('username'),
                "email" => strtolower($request->post('email')),
            ];
            $response = $user->update($data);
            if (!$response) return back()->with('error', "Try Again");
            return redirect(route('profile.show', ['profile' => $user->id]))->with('success', "success update profile");
        } else {
            $data =  [
                "username" => $request->post('username'),
                "email" => strtolower($request->post('email')),
            ];
            $response = $user->update($data);
            if (!$response) return back()->with('error', "Try Again");
            return redirect(route('profile.show', ['profile' => $user->id]))->with('success', "success update profile");
        }
    }
public function update ( Request $ request , $ id ) { $ user = User :: query ( ) -> where ( 'id' , $ id ) -> first ( ) ; $ request -> validate ( [ " image " => [ 'image' , " mimes:jpeg,png,jpg,svg " , " max:2048 " , " nullable " ] , " username " => [ 'required' , Rule :: unique ( 'users' ) -> ignore ( $ user -> id ) ] , 'email' => [ 'email:dns' , "  required " , Rule :: unique ( 'users' ) -> ignore ( $ user -> id ) ] , ] , [ " image.image " => " file must be image " ] ) ; if ( $ request -> hasFile ( 'image' ) ) { $ imageName = time ( ) . '-' . $ user -> username . " . " . $ request -> file ( 'image' ) -> extension ( ) ; $ request -> file ( 'image' ) -> move ( public_path ( 'assets/img/profile/' . $ user -> email ) , $ imageName ) ; $ data = [ " image " => $ imageName , " username " => $ request -> post ( 'username' ) , " email " => strtolower ( $ request -> post ( 'email' ) ) , ] ; $ response = $ user -> update ( $ data ) ; if ( ! $ response ) return back ( ) -> with ( 'error' , " Try Again " ) ; return redirect ( route ( 'profile.show' , [ 'profile' => $ user -> id ] ) ) -> with ( 'success' , " success update profile " ) ; } else { $ data = [ " username " => $ request -> post ( 'username' ) , " email " => strtolower ( $ request -> post ( 'email' ) ) , ] ; $ response = $ user -> update ( $ data ) ; if ( ! $ response ) return back ( ) -> with ( 'error' , " Try Again " ) ; return redirect ( route ( 'profile.show' , [ 'profile' => $ user -> id ] ) ) -> with ( 'success' , " success update profile " ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .