vendredi 25 septembre 2015

How do I update user profile? Laravel-5

Just want to start by saying I have no clue what I'm doing... I have a user_info table that looks like this

    Schema::create('user_info', function(Blueprint $table){
        $table->increments('id');
        $table->unsignedInteger('user_id');
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
        $table->string('address');
        $table->string('city');
        $table->string('state');
        $table->string('zip');
        $table->text('description');
        $table->text('experience');
        $table->timestamps();
    });   

I'm having trouble creating the update controller which looks like this right now.

public function update(Request $request)
{

  $user = $request->user();
  $data['description'] = $request->input('description');
  $data['experience']=$request->input('experience');

  $user->user_info -> $data->save();
}

again...no clue what I'm doing...

and this be my form:

    <div class='col-md-10 well form-well'>
        {!! Form::open(['method' => 'PATCH', 'action'=> ['UserController@update', Request::user()->id]]) !!}
        <div class='row'>
                <div class='form-group'>
                    <div class='col-md-2'>
                        {!! Form::label('description', 'About You')!!}
                    </div>
                    <div class='col-md-7'>
                        {!! Form::textarea('description', null, ['class'=>'form-control', 'rows'=>'3'])!!}
                    </div>
                </div>
        </div>
        <div class='row'>
                <div class='form-group'>
                    <div class='col-md-2'>
                        {!! Form::label('experience', 'Experience and Skills')!!}
                    </div>
                    <div class='col-md-7'>
                        {!! Form::text('experience', null, ['class'=>'form-control'])!!}
                    </div>
                </div>
        </div>
        <div class='form-group'>            
            {!! Form::submit('Save Changes',['class'=> 'btn btn-md btn-success']) !!}
            {!! Form::close()!!}
    </div>

Any help is appreciated. Thank you!




Aucun commentaire:

Enregistrer un commentaire