Laravel 我已经通过make:auth生成了用户登录和注册,现在我想更新详细信息

Laravel 我已经通过make:auth生成了用户登录和注册,现在我想更新详细信息,laravel,Laravel,我已经通过make:auth生成了用户auth,它没有“编辑详细信息”字段,现在我想编辑电子邮件和联系人等详细信息,其他人则将其禁用。我尝试从RegisterController复制代码我刚将创建方法更改为更新方法,如果您有编辑详细信息的准备好的模板,请与我共享,我搜索了许多准备好的模板,但没有找到,我只想要模板,它将与生成的身份验证或我的问题的解决方案兼容,因为现在它没有更新详细信息 1) 视图:编辑_profile.blade.php <form method="POST" acti

我已经通过make:auth生成了用户auth,它没有“编辑详细信息”字段,现在我想编辑电子邮件和联系人等详细信息,其他人则将其禁用。我尝试从RegisterController复制代码我刚将创建方法更改为更新方法,如果您有编辑详细信息的准备好的模板,请与我共享,我搜索了许多准备好的模板,但没有找到,我只想要模板,它将与生成的身份验证或我的问题的解决方案兼容,因为现在它没有更新详细信息

1) 视图:编辑_profile.blade.php

<form method="POST" action="/profile">

    @csrf

    <div class="form-group row">
        <label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>

        <div class="col-md-6">
            <input id="name"  disabled type="text" class="form-control" value='{{$user->name}}' name="name"> 
        </div>
    </div>

    <div class="form-group row">
        <label for="username" class="col-md-4 col-form-label text-md-right">{{ __('Student Number') }}</label>

        <div class="col-md-6">
        <input id="username" disabled type="text" class="form-control" name="username" value="{{$user->username}}">
        </div>
    </div>

    <div class="form-group row">
        <label for="age" class="col-md-4 col-form-label text-md-right">{{ __('Age') }}</label>

        <div class="col-md-6">
            <input id="age" disabled type="text" class="form-control" name="age" value="{{$user->age}}"
                required> @if ($errors->has('age'))
            <span class="invalid-feedback" role="alert">
                        <strong>{{ $errors->first('age') }}</strong>
            </span> @endif
        </div>
    </div>

    <div class="form-group row">
        <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

        <div class="col-md-6">
            <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{$user->email}}"
                required> @if ($errors->has('email'))
            <span class="invalid-feedback" role="alert">
                    <strong>{{ $errors->first('email') }}</strong>
                </span> @endif
        </div>
    </div>


    <div class="form-group row">
        <label for="contact" class="col-md-4 col-form-label text-md-right">{{ __('Contact Number') }}</label>

        <div class="col-md-6">
            <input id="contact" type="text" class="form-control{{ $errors->has('contact') ? ' is-invalid' : '' }}" name="contact" value="{{$user->contact}}"
                required> @if ($errors->has('contact'))
            <span class="invalid-feedback" role="alert">
                        <strong>{{ $errors->first('contact') }}</strong>
                    </span> @endif
        </div>
    </div>

    <div class="form-group row mb-0">
        <div class="col-md-6 offset-md-4">
            <button type="submit" class="btn btn-primary">
                {{ __('Update Details') }}
            </button>
        </div>
    </div>
</form>

我注意到了一些问题

  • 你是
    ProfileController@update
    方法接受数组,但不会传递数组
  • 您没有对经过身份验证的用户调用
    update

  • 您正在发布到
    /profile
    ,查看您的路线,如果是为了更新化身而不是用户数据

  • 将您的表格更改为:

    <form method="POST" action="/profile/edit">
    

    问题是什么?你收到错误了吗?@RossWilson只是没有更新数据,没有错误
    //User Profile
    Route::get('/profile', 'ProfileController@profile');
    Route::post('profile', 'ProfileController@update_avatar');
    Route::get('/profile/edit', 'ProfileController@edit');
    Route::post('profile/edit', 'ProfileController@update');
    
    <form method="POST" action="/profile/edit">
    
    public function update(Request $request)
    {
        $data = $this->validate($request, [
            'email'   => 'required|email',
            'contact' => 'required',
        ]);
    
        auth()->user()->update($data);
    
        return auth()->user();
    }
    
    public function update(Request $request)
    {
        //check validation 
    
    
        Auth::user()->update($request);
    
        return true;
    }