只想說我不知道我在做什麼...... 我有一個user_info表中,看起來像這樣如何更新用戶配置文件? Laravel-5
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();
});
我無法創建更新控制器開始其看起來像現在這樣。
public function update(Request $request)
{
$user = $request->user();
$data['description'] = $request->input('description');
$data['experience']=$request->input('experience');
$user->user_info -> $data->save();
}
再次...不知道我在做什麼...
,這是我的表格:
<div class='col-md-10 well form-well'>
{!! Form::open(['method' => 'PATCH', 'action'=> ['[email protected]', 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>
更新:我能像這樣更新:
$user->user_info->description = $data['description'];
$user->user_info->experience = $data['experience'];
$user->user_info->save();
但是,有沒有辦法,我可以這樣做:
$user->user_info->$request::Input::all();
$user->user_info->save();
好吧,那 - '$用戶> USER_INFO - > $數據 - >保存();'是一個非常奇怪的行...頁面報告有關任何錯誤? – BlitZ
我收到一個錯誤異常:數組到字符串的轉換。通常如何寫? – joejoeso
我在Laravel沒有經驗,但是,它是純粹的PHP消息。我建議通過手冊瞭解應該如何正確完成。另外我會建議嘗試像'$ data-> save()'或'$ user-> user_info = $ data-> save();'。 – BlitZ