2016-09-13 4 views
0

今は私の予定を削除することはできますが、保存することはできません。laravelに予定を保存する

これは私の削除機能である:

public function destroy($id) 
{ 
    $appointment = Appointment::find($id);  
    $appointment->delete(); 

    return redirect('/appointments'); 
} 

そしてこれは私のそれが更新されないです何らかの理由で機能

public function update($id) 
{ 
    $save_appointment = Appointment::find($id); 
    $save_appointment->save(); 

    return redirect('/appointments'); 
} 

を保存しています。 idは100%正確です。私は間違って何をしています。あなたは本当に重要な何かが欠けている

protected $fillable = [ 
    'gender', 'options', 'user_id', 
]; 

/** 
* The attributes that should be hidden for arrays. 
* 
* @var array 
*/ 
protected $hidden = [ 
    'password', 'remember_token', 
]; 
+0

あなたは何を更新していますか? –

答えて

1

あなたの機能は次のようにする必要があります:

public function update(Request $request, $id) 
    { 
    $save_appointment = Appointment::find($id); 
    $save_appointment->update($request->all()); 
    $save_appointment->save(); 

    return redirect('/appointments'); 
} 
+0

はい!ありがとうございました! – twoam

0

、全体の情報を更新する:私は私の予定modelこの中で持っているので、それをです。

のコードで話しましょう:

public function update(Request $request) { 
    $save_appointment = Appointment::find($request->id); 
    $save_appointment->gender = $request->gender; 
    $save_appointment->options = $request->options; 
    $save_appointment->user_id = $request->user_id; 
    $save_appointment->save(); 

    return redirect('/appointments'); } 
+0

いいえ私はこのような予定を作成しました: '$ tasks = Appointment :: create($ request-> all());'それはそれのように更新できますか?あなたのフォームに20の質問があるときに膨大になるので、そんなことをコード化したくありません。 – twoam

+0

はい、あなたはそれをチェックすることができます。何か問題があった場合は、ここにコードを貼り付けてください。 – Martin

+0

助けてくれてありがとう。 Zloterは答えをくれました:) – twoam

関連する問題