誰もが一日の種類!私の問題の本質はこれです: 2つのモデルがありますContact and PhoneNum!モデルでの関係:編集接点の形でLaravel sync hasMany belongsTo配列を持つ
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
protected $table = 'contacts';
public function phoneNums()
{
return $this->hasMany('App\Models\PhoneNum');
}
}
PHONENUMモデル
class PhoneNum extends Model
{
protected $table = 'phoneNums';
protected $fillable = ['phone_num'];
public function contact()
{
return $this->belongsTo('App\Models\Contact');
}
}
、私はその名前と、この連絡先の電話番号を持つ配列を取得します。
ContactController
public function update(Request $request, $id)
{
$contact = Contact::find($id);
$contact->name = $request->name;
$contact->save();
//what should I do with the array $request->phoneNums ????
return redirect('/');
}
私は、IDに接触して、これらの新しい電話番号を同期することはできません。これで私を助けることができますか?