doutongxuan1614 2016-08-15 05:11
浏览 48
已采纳

如何在laravel 5.1中更新用户表中的值

I have an issue I cannot update my user table . I don't know where he problem is.Whenever I submit my updated info it cannot updated. It Does not show any error. But the table is not updated. Please Help me guys. My Controller is

public function getUpdate() {

        $profile = Auth::user();
        return view('admin.article.edit')
        ->with('profile',$profile);
    }

    public function postUpdate(Request $request ) {
$profile = Auth::user();

        $this->validate($request, [
            'name' => 'required|max:120',
            'username' => 'required|max:80',
            'email' => 'required',
            'password' => 'required'
            ]);

         // save users table
        $profile = Auth::user();
        // $user = new App\User;
        $profile->name = $request->input('name');
        $profile->email = $request->input('email');
        $profile->username = $request->input('username');
        $profile->password = $request->input('password');
        $profile->update();
}

My edit.blade.php page is

<?php $active="profile"; ?>
@extends('admin.dashboard')
@section('content')
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        User Profile
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">User profile</li>
      </ol>
    </section>

<!-- Main content -->
    <section class="content">
      <div class="row">
        <!-- left column -->
        <div class="col-md-10">
          <!-- general form elements -->
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">Quick Example</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form action="{{ route('update') }}" role="form" method="post" enctype="multipart/form-data">
              <div class="box-body">
                <div class="form-group">
                  <label for="name">Name</label>
                  <input type="text" class="form-control" name="name" id="name" {{ $errors->has('name') ? 'class=has-error' : '' }} value="{{ Request::old('name') ? Request::old('name') : isset($profile) ? $profile->name : '' }}">
                </div>
                <div class="form-group">
                  <label for="username">User Name</label>
                  <input type="text" class="form-control" name="institute" id="institute" {{ $errors->has('username') ? 'class=has-error' : '' }} value="{{ Request::old('institute') ? Request::old('username') : isset($profile) ? $profile->institute : '' }}">
                </div>
</div>
              <!-- /.box-body -->

              <div class="box-footer">
                <button type="submit" class="btn btn-primary">Submit</button>
                <input type="hidden" name="_token" value="{{ Session::token() }}">
                <input type="hidden" name="id" value="{{ $profile->id }}">
              </div>
            </form>
          </div>
          <!-- /.box -->

        </div>
        <!--/.col (left) -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
@endsection  

My route file is

Route::get('/profile/edit', [
                    'uses' => 'ProfileController@getUpdate',
                    'as' => 'edit'
            ]);

        Route::post('profile/update', [
                    'uses' => 'ProfileController@postUpdate',
                    'as' => 'update'
            ]);
  • 写回答

5条回答 默认 最新

  • dongyuqi3808 2016-09-07 10:59
    关注

    In your route you should write this

    Route::get('/profile/{profile_id}/edit', [
                        'uses' => 'ProfileController@getUpdate',
                        'as' => 'edit'
                ]);
    
            Route::post('profile/update', [
                        'uses' => 'ProfileController@postUpdate',
                        'as' => 'update'
                ]);
    

    And in your controller you should write this

    public function getUpdate() {
            $divisions = Division::all();
            $districts = District::all();
            $dcategories = Dcategory::all();
            $profile = Auth::user();
    
            return view('admin.article.edit')
            ->with('divisions',$divisions)
            ->with('districts',$districts)
            ->with('dcategories',$dcategories)
            ->with('profile',$profile);
        }
    
        public function postUpdate(Request $request ) {
    
            $this->validate($request, [
                'name' => 'required|max:120',
                'fee' => 'required|max:5',
                'division_id' => '',
                'district_id' => '',
                'dcategory_id' => '',
                'education' => '',
                'institute' => '',
                'specialty' => '',
                'hospital' => '',
                'time' => '',
                'phone' => '',
                'image' =>''            
                ]);
    
    
            $doctor = Auth::user();
            $doctor->name = $request['name'];
            $doctor->division_id = $request['division_id'];
            $doctor->district_id = $request['district_id'];
            $doctor->dcategory_id = $request['dcategory_id'];
            $doctor->institute = $request['institute'];
            $doctor->education = $request['education'];
            $doctor->specialty = $request['specialty'];
            $doctor->hospital = $request['hospital'];
            $doctor->phone = $request['phone'];
            $doctor->time = $request['time'];
            $doctor->fee = $request['fee'];
    
            // $photo = Photo::find($request['id']);
            $logo=$request->file('image');
            if(!empty($logo)) {
                $upload='uploads/logo';
                $filename=$logo->getClientOriginalName();
                $success=$logo->move($upload,$filename);
    
                $doctor->image = $filename;
            }
    

    This might solve your problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 ImportError: DLL load failed while importing _iterative: 找不到指定的模块。
  • ¥15 控制工程研究生方向选择
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败