lundi 25 février 2019

One form is working while other form is not working in laravel 5.4

I've UserController in which I've two options -

  1. For Updating Profile
  2. For Updating Password

    namespace App\Http\Controllers;

    use Illuminate\Http\Request; use Illuminate\Support\Facades\Input; use App\User; use Auth; use Hash;

    class UserController extends Controller { public function profile(){ return view('profile', array('user' => Auth::user())); }

    public function update_avatar(Request $request){
        if(isset($request->avatar) && $request->avatar->getClientOriginalName()){
            $ext = $request->avatar->getClientOriginalExtension();
            $file = date('YmdHis').rand(1,99999).'.'.$ext;
            $request->avatar->storeAs('public/avatar',$file);
    
        }
        else
        {
            $user = Auth::user();
            if(!$user->avatar)
                $file = '';
            else
                $file = $user->avatar;
        }
        $user = Auth::user();
            $user->avatar = $file;
            $user->name = $request->name;
            $user->email = $request->email;
            $user->mb_number = $request->mb_number;
            $user->home_town = $request->home_town;
            $user->save();
    
        return view('profile', array('user' => Auth::user()));
    
    }
    
    public function update_password(Request $request){
        $user = Auth::user();
        if(Hash::check(Input::get('old_password'), $user['password']) && Input::get('new_password') == Input::get('confirm_new_password')){
            $user->password = bcrypt(Input::get('new_password'));
            $user->save();
        }
        return view('profile', array('user' => Auth::user()));
    }
    
    

    }

In my view blade, I've two forms -

  1. update_avatar for updating profile like name, phone number and avatar.
  2. update_password for updating password.

            </div>
            <div class="widget-user-image">
              <img class="img-circle" src="" alt="User Avatar">
    
            </div>
            <div class="box-footer">
              <div class="row">
                <div class="col-sm-4 border-right">
                  <div class="description-block">
                    <h5 class="description-header"></h5>
                    <span class="description-text">Email</span>
                  </div>
                  <!-- /.description-block -->
                </div>
                <!-- /.col -->
                <div class="col-sm-4 border-right">
                  <div class="description-block">
                    <h5 class="description-header"></h5>
                    <span class="description-text"></span>
                  </div>
                  <!-- /.description-block -->
                </div>
                <!-- /.col -->
                <div class="col-sm-4">
                  <div class="description-block">
                    <h5 class="description-header"></h5>
                    <span class="description-text">Phone No.</span>
                  </div>
                  <!-- /.description-block -->
                </div>
                <!-- /.col -->
              </div>
              <!-- /.row -->
            </div>
            <!--
            <div class="box-footer no-padding">
              <ul class="nav nav-stacked">
                <li><a href="#">Projects <span class="pull-right badge bg-blue">31</span></a></li>
                <li><a href="#">Tasks <span class="pull-right badge bg-aqua">5</span></a></li>
                <li><a href="#">Completed Projects <span class="pull-right badge bg-green">12</span></a></li>
                <li><a href="#">Followers <span class="pull-right badge bg-red">842</span></a></li>
              </ul>
            </div>
            -->
          </div>
          </div>
    
              <section class="content">
                <div class="container-fluid">
                    <form action="/profile" enctype="multipart/form-data" method="POST">
                        <div class="form-group">
                            <div class="form-group">
                                <label for="name">Name</label>
                                <input type="text" name="name" class="form-control" id="name" placeholder="Title" value="">
                            </div>
                            <div class="form-group">
                                <label for="email">Email</label>
                                <input type="text" name="email" class="form-control" id="email" placeholder="Description" value="" readonly>
                            </div>
                            <div class="form-group">
                                <label for="mb_number">Mobile No.</label>
                                <input type="text" name="mb_number" class="form-control" id="mb_number" placeholder="Schedule" value="">
                            </div>
                            <div class="form-group">
                                <label for="home_town">Home Town</label>
                                <input type="text" name="home_town" class="form-control" id="home_town" placeholder="Deadline" value="">
                            </div>
                            <div class="form-group">
                                <label>Update Profile Image</label>
                                <input type="file" name="avatar">
                                @if($user->avatar)
                                <img src="" style="width:150px;">
                                @endif
                            </div>
                        <input type="hidden" name="_token" value=""
                        <a href="" type="submit" class="btn btn-info"></a>
                        <button type="submit" class="btn btn-primary">Update</button>
                    </div>
                </div>
    </section>
    
    <section class="content">
                <div class="container-fluid">
                    <form action="/profile" enctype="multipart/form-data" method="POST">
                        <div class="form-group">
                            <div class="form-group">
                                <label for="old_password">Old Password</label>
                                <input type="password" name="old_password" class="form-control" id="old_password" placeholder="Old Password">
                            </div>
                            <div class="form-group">
                                <label for="new_password">New Password</label>
                                <input type="password" name="new_password" class="form-control" id="new_password" placeholder="New Password">
                            </div>
                            <div class="form-group">
                                <label for="confirm_new_password">Confirm New Password </label>
                                <input type="password" name="confirm_new_password" class="form-control" id="confirm_new_password" placeholder="Confirm New Password">
                            </div>
                        <input type="hidden" name="_token" value=""
                        <a href="" type="submit" class="btn btn-info"></a>
                        <button type="submit" class="btn btn-primary">Update Password</button>
                    </div>
                </div>
    </section>
    
    

update_password function is working fine but update_avatar function is not working neither it's showing any error. I've tried dd($user) but still not giving output to dd.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire