2016-11-04 4 views
0

로그인 후 사용자 프로필을 업데이트하려고하는데 제대로 작동하고 성공적으로 업데이트되었습니다. 데이터베이스 테이블에 아무 것도 삽입되지 않았으므로 본질적으로보기에는 업데이트 된 양식이 표시되지 않습니다. 전지. 제발 내가 어디 잘못이 높게 평가됩니다 감사합니다 누구와 함께 아이디어를주십시오, 감사합니다.데이터가 Laravel 양식의 데이터베이스에 저장되지 않습니다.

CONTROLLER 업데이트 기능

public function update(Request $request) 
    { 

     $rules = [ 
      'name' => 'required', 
      'email' => 'required', 
      'phone' => 'required|numeric', 
      'country' => 'required', 
      'gender' => 'required', 
      'birthday' => 'required', 
      'fb' => 'url', 
      'twitter' => 'url', 
      'gp' => 'url', 
      'instagram' => 'url', 
      'personal_site' => 'url', 
      'aboutme' => 'url', 
      'linkedin' => 'url', 
      'pinterest' => 'url' 

     ]; 

     $data= $request->all(); 
     $validator = Validator::make($data, $rules); 
     if($validator->fails()){ 
      return Redirect::back()->withInput()->withErrors($validator); 
     } 
     $user = Auth::user(); 

     $user->name = $data['name']; 
     $user->email = $data['email']; 
     $user->phone = $data['phone']; 
     $user->country = $data['country']; 
     $user->birthday = $data['birthday']; 
     $user->address = $data['address']; 
     if($user->save()) { 
      $profile_id = $user->id; 
      $profile = Profile::find($profile_id); 
      if(count($profile) > 0) { 
      $profile->gender = $data['gender']; 
      $profile->city = $data['city']; 
      $profile->state = $data['state']; 
      $profile->aboutmyself = $data['aboutmyself']; 
      $profile->fb = $data['fb']; 
      $profile->twitter = $data['twitter']; 
      $profile->gp = $data['gp']; 
      $profile->instagram = $data['instagram']; 
      $profile->personal_site = $data['personal_site']; 
      $profile->aboutme = $data['aboutme']; 
      $profile->linkedin = $data['linkedin']; 
      $profile->pinterest = $data['pinterest']; 
      // $profile = $user->profile()->save($profile); 
      $profile->save(); 

} 
     } else { 
      return redirect()->back()->withInput()->withInfo("Something went wrong. Please, try again"); 
     } 
     return redirect()->route('profile')->withSuccess("Your Profile Successfully Updated."); 

    } 

MY VIEW (프로파일 edit.blade.php)

<div class="form-group row"> 
       {!! Form::model($user, array('route' => 'post.edit.profile', 'method' => 'post', 'class' => 'form-horizontal')) !!} 

       {!! Form::label('name', "Full Name", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-8"> 
        <div class="row"> 
        <div class="col-md-9"> 
         {!! Form::text('name', null, array('class' => 'form-control', 'placeholder' => 'Your Full Name', 'required' => 'required')) !!} 
        </div> 
        </div> 
       </div> 
       </div> 
       <div class="form-group row"> 
       {!! Form::label('email', "Email Address", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-6"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon1"> 
           <i class="material-icons md-18 text-muted">mail</i> 
          </span> 
        {!! Form::email('email', null, array('class' => 'form-control', 'placeholder' => '', 'required' => 'required')) !!} 
        </div> 
       </div> 
       </div> 
       <div class="form-group row"> 
       {!! Form::label('phone', "Phone Number", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-6"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon1"> 
           <i class="material-icons md-18 text-muted">mail</i> 
          </span> 
        {!! Form::text('phone', null, array('class' => 'form-control', 'placeholder' => 'e.g. +8801711223344', 'required' => 'required')) !!} 
        </div> 
       </div> 
       </div> 


       <div class="form-group row"> 
       {!! Form::label('gender', "Gender", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        {!! Form::select('gender', $gender, array('class' => 'c-select form-control', 'id' => '', 'required' => 'required')) !!} 
       </div> 
       </div> 


       <div class="form-group row"> 
       {!! Form::label('birthday', "Birthday", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 

        {!! Form::text('birthday', null, array('class' => 'datepicker form-control', 'placeholder' => '01/28/2016','id' => 'birthday', 'required' => 'required')) !!} 
        </div> 
       </div> 
       </div> 
          <div class="form-group row"> 
       {!! Form::label('address', "Address", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('address', null, array('class' => 'form-control', 'placeholder' => 'Street No., Area...','id' => 'address', 'required' => 'required')) !!} 
        </div> 
       </div> 
       </div> 
             <div class="form-group row"> 
       {!! Form::label('city', "City", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('city', $user->profile->city, array('class' => 'form-control', 'placeholder' => 'City', 'required' => 'required')) !!} 
        </div> 
       </div> 
       </div> 
       <div class="form-group row"> 
      {!! Form::label('state', "State", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('state', $user->profile->state, array('class' => 'form-control', 'placeholder' => 'State', 'required' => 'required')) !!} 
        </div> 
       </div> 
       </div> 


       <div class="form-group row"> 
       {!! Form::label('country', "Country", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-8"> 
        <div class="row"> 
        <div class="col-md-6"> 
        {!! Form::text('country', null, array('class' => 'form-control', 'placeholder' => 'Country','id' => '')) !!} 

        </div> 
        </div> 
       </div> 
       </div> 




          <div class="form-group row"> 
       {!! Form::label('aboutmyself', "About Me", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::textarea('aboutmyself', Auth::user()->profile->aboutmyself, array('class' => 'form-control', 'rows' => 4, 'placeholder' => 'About Yourself')) !!} 
        </div> 
       </div> 
       </div> 

       <div class="form-group row"> 
      {!! Form::label('fb', "Facebook Link", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('fb', $user->profile->fb, array('class' => 'form-control', 'placeholder' => 'https://facebook.com/username')) !!} 
        </div> 
       </div> 
       </div> 

       <div class="form-group row"> 
      {!! Form::label('twitter', "Twitter Link", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('twitter', $user->profile->twitter, array('class' => 'form-control', 'placeholder' => 'https://twitter.com/username')) !!} 
        </div> 
       </div> 
       </div> 

          <div class="form-group row"> 
      {!! Form::label('gp', "Google+ Link", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('gp', $user->profile->gp, array('class' => 'form-control', 'placeholder' => 'https://plus.google.com/+username')) !!} 
        </div> 
       </div> 
       </div> 

       <div class="form-group row"> 
      {!! Form::label('personal_site', "Personal Site", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('personal_site', $user->profile->personal_site, array('class' => 'form-control', 'placeholder' => 'http://www.mywebsite.me')) !!} 
        </div> 
       </div> 
       </div> 

       <div class="form-group row"> 
      {!! Form::label('instagram', "Instagram Link", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('instagram', $user->profile->instagram, array('class' => 'form-control', 'placeholder' => 'https://www.instagram.com/username')) !!} 
        </div> 
       </div> 
       </div> 

       <div class="form-group row"> 
     {!! Form::label('linkedin', "LinkedIn Link", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('linkedin', $user->profile->linkedin, array('class' => 'form-control', 'placeholder' => 'https://www.linkedin.com/username')) !!} 
        </div> 
       </div> 
       </div> 

       <div class="form-group row"> 
      {!! Form::label('pinterest', "Pinterest Link", array('class' => 'col-sm-3 control-label')) !!} 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon2"> 
           <i class="material-icons md-18 text-muted">language</i> 
          </span> 
        {!! Form::text('pinterest', $user->profile->pinterest, array('class' => 'form-control', 'placeholder' => 'https://www.pinterest.com/username')) !!} 
        </div> 
       </div> 
       </div> 

      <!-- <div class="form-group row"> 
       <label for="password" class="col-sm-3 form-control-label">Change Password</label> 
       <div class="col-sm-6 col-md-4"> 
        <div class="input-group"> 
        <span class="input-group-addon" id="basic-addon3"> 
           <i class="material-icons md-18 text-muted">lock</i> 
          </span> 
        <input type="text" class="form-control" placeholder="Enter new password"> 
        </div> 
       </div> 
       </div> --> 
       <div class="form-group row"> 
       <div class="col-sm-8 col-sm-offset-3"> 
        <div class="media"> 
        <div class="media-left"> 
        {!! Form::submit('Save Changes', array('class' => 'btn btn-success')) !!} 
        </div> 
        <!-- <div class="media-body media-middle p-l-1"> 
         <label class="c-input c-checkbox"> 
         <input type="checkbox" checked> 
         <span class="c-indicator"></span> Subscribe to Newsletter 
         </label> 
        </div> --> 
        </div> 
       </div> 
       </div> 
      {!! Form::close() !!} 

사용자 모델 (User.php)

<?php 

namespace App; 

use Illuminate\Auth\Authenticatable; 
use Illuminate\Database\Eloquent\Model; 
use Illuminate\Auth\Passwords\CanResetPassword; 
use Illuminate\Foundation\Auth\Access\Authorizable; 
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; 
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; 
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; 
use Zizaco\Entrust\Traits\EntrustUserTrait; 

class User extends Model implements AuthenticatableContract, 
            AuthorizableContract, 
            CanResetPasswordContract 
{ 
    use Authenticatable, Authorizable, CanResetPassword,EntrustUserTrait { 
     EntrustUserTrait::can as may; 
     Authorizable::can insteadof EntrustUserTrait; 
    } 

    /** 
    * The database table used by the model. 
    * 
    * @var string 
    */ 
    protected $table = 'users'; 

    /** 
    * The attributes that are mass assignable. 
    * 
    * @var array 
    */ 
    protected $fillable = ['name', 'email', 'password']; 

    /** 
    * The attributes excluded from the model's JSON form. 
    * 
    * @var array 
    */ 
    protected $hidden = ['password', 'remember_token']; 

    public function profile(){ 
     return $this->hasOne('App\Profile','user_id','id'); 
    } 

    public function pending(){ 
     return $this->hasMany('App\PendingTransfers', 'user_id', 'id'); 
    } 

    public function transaction(){ 
     return $this->hasMany('App\Transaction', 'user_id', 'id'); 
    } 
} 

ROUTE

Route::group(array('middleware' => 'auth'), function() 
{ 

    Route::get('logout', ['as' => 'logout', 'uses' => 'Auth\[email protected]']); 
    Route::get('profile', ['as' => 'profile', 'uses' => '[email protected]']); 
    Route::get('edit-profile', ['as' => 'edit.profile', 'uses' => '[email protected]']); 
    Route::post('edit-profile', ['as' => 'post.edit.profile', 'uses' => '[email protected]']); 
    Route::post('edit-photo', ['as' => 'post.edit.photo', 'uses' => '[email protected]']); 
    Route::get('dashboard', array('as' => 'dashboard', 'uses' => 'Auth\[email protected]')); 
    Route::get('change-password', array('as' => 'password.change', 'uses' => 'Auth\[email protected]')); 
    Route::post('change-password', array('as' => 'password.doChange', 'uses' => 'Auth\[email protected]')); 

UPDATE :

if($user->save()) { 
      $profile_id = $user->id; 
      $profile = Profile::find($profile_id); 
      if(count($profile) > 0) { 
      $profile->gender = $data['gender']; 
      $profile->city = $data['city']; 
      $profile->state = $data['state']; 
      $profile->aboutmyself = $data['aboutmyself']; 
      $profile->fb = $data['fb']; 
      $profile->twitter = $data['twitter']; 
      $profile->gp = $data['gp']; 
      $profile->instagram = $data['instagram']; 
      $profile->personal_site = $data['personal_site']; 
      $profile->aboutme = $data['aboutme']; 
      $profile->linkedin = $data['linkedin']; 
      $profile->pinterest = $data['pinterest']; 
      // $profile = $user->profile()->save($profile); 
      $profile->save(); 

또는 아마도 VIEW 오프닝에서 양식 경로/변수 : 프롬프트 응답하지만 그 암이 고장이 시점에서 CONTROLLER 기능에서있을 생각하지만 그것을 해결하지 않았다 주셔서 감사합니다 모든 테이블을 설정 사용자 모델에서 $ 사용자

{!! Form::model($user, array('route' => 'post.edit.profile', 'method' => 'post', 'class' => 'form-horizontal')) !!} 

답변

0

$fillable

protected $fillable = ['name', 'email', 'password','phone','country','gender']; 
필드
관련 문제