samedi 25 novembre 2017

Lrarvel sync hasMany with belongsTo array

Kind time of day everyone! The essence of my problem is this: there are two models Contact and PhoneNum! relationships in models:

 use Illuminate\Database\Eloquent\Model;

class Contact extends Model
{
    protected $table = 'contacts';
    public function phoneNums()
    {
        return $this->hasMany('App\Models\PhoneNum');
    }
}

PhoneNum model

class PhoneNum extends Model
{
    protected $table = 'phoneNums';
    protected $fillable = ['phone_num'];

    public function contact()
    {
        return $this->belongsTo('App\Models\Contact');
    }
}

In the form of editing contact, I get its name and an array with the phone numbers of this 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('/');
    }

I can not synchronize these new phone numbers with a contact on id. Can you help me with this?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iPibJ9
via IFTTT

Aucun commentaire:

Enregistrer un commentaire