app/Http/Controllers/user_controller.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)
    {
        $update = user::find($id);
        $profile_name = $request->profile_name;
        $profile= $request-> file('profile');
        if ($profile !='') {
            Storage::delete('public/profile/'. $update->profile);
        $this->validate($request, [
            'name' => 'required',
            'profile'  => 'image|mimes:jpeg,png,jpg',
        ]);
        $profile_name = $request->file('profile');
        $nama_file = time() . "_" . $profile->getClientOriginalName();
        $tujuan_upload = Storage::putFileAs('public/profile/', $request->file('profile'), $nama_file);
        $update->update([
            'name' => $request['name'],
            'profile' => $nama_file,
        ]);
        } else{
            $this->validate($request, [
            'name' => 'required',
            'email' => ['required', 'email' ,
                        Rule::unique('users', 'email')
                        ->ignore($update->id)],
            'username' => ['required', 'string', 'max:500','alpha_dash',
                        Rule::unique('users', 'username')
                         ->ignore($update->id)],
            'password' => 'confirmed',
        ]);
            $update->update([
            'name' => $request['name'],
            'email' => $request['email'],
            'username' => $request['username'],
            'password' => bcrypt($request['password']),
            ]);}
        return redirect()->back()->withSuccess('User Update Succesfully!');;
    }
public function update ( Request $ request , $ id ) { $ update = user :: find ( $ id ) ; $ profile_name = $ request -> profile_name ; $ profile = $ request -> file ( 'profile' ) ; if ( $ profile != '' ) { Storage :: delete ( 'public/profile/' . $ update -> profile ) ; $ this -> validate ( $ request , [ 'name' => 'required' , 'profile' => 'image|mimes:jpeg,png,jpg' , ] ) ; $ profile_name = $ request -> file ( 'profile' ) ; $ nama_file = time ( ) . " _ " . $ profile -> getClientOriginalName ( ) ; $ tujuan_upload = Storage :: putFileAs ( 'public/profile/' , $ request -> file ( 'profile' ) , $ nama_file ) ; $ update -> update ( [ 'name' => $ request [ 'name' ] , 'profile' => $ nama_file , ] ) ; } else { $ this -> validate ( $ request , [ 'name' => 'required' , 'email' => [ 'required' , 'email' , Rule :: unique ( 'users' , 'email' ) -> ignore ( $ update -> id ) ] , 'username' => [ 'required' , 'string' , 'max:500' , 'alpha_dash' , Rule :: unique ( 'users' , 'username' ) -> ignore ( $ update -> id ) ] , 'password' => 'confirmed' , ] ) ; $ update -> update ( [ 'name' => $ request [ 'name' ] , 'email' => $ request [ 'email' ] , 'username' => $ request [ 'username' ] , 'password' => bcrypt ( $ request [ 'password' ] ) , ] ) ; } return redirect ( ) -> back ( ) -> withSuccess ( 'User Update Succesfully!' ) ; ; }
Update the specified resource in storage.
Update the specified resource in storage .
// $this->validate($request, [ //     'name' => 'required', //     'email' => 'required', //     'password' => 'required|string|min:6|confirmed', //     'profile'  => 'required|image|mimes:jpeg,png,jpg', // ]); // $update = user::find($id); // $update->name = $request->name; // $update->email = $request->email; // $update->password = bcrypt($request->password); // $update->update($request->only('profile')); // if ($request->hasFile('profile')) { //     $file = $request->file('profile'); //     $nama_file = time() . "_" . $file->getClientOriginalName(); //     $tujuan = Storage::putFileAs('public/profile/', $request->file('profile'), $nama_file); //     $update->profile = $nama_file; //     $update->save(); // isi dengan nama folder tempat kemana file diupload