Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Many to Many relation how to override? #38

Open
lgt opened this issue Sep 13, 2014 · 0 comments
Open

Many to Many relation how to override? #38

lgt opened this issue Sep 13, 2014 · 0 comments

Comments

@lgt
Copy link

lgt commented Sep 13, 2014

I try to override the base controllers postNew() method in my custom Controller like assigning many to many relationship but I get error

Call to undefined method Illuminate\Database\Query\Builder::sync()

the overrided looks like

public function postNew() {

    $record = $this->model->getNew(Input::all());
    $record->campaign_title= Input::get('campaign_title');

    $valid = $this->validateWithInput === true ? $record->isValid(Input::all()) : $record->isValid();

    if (!$valid)
        return Redirect::to('admin/' . $this->new_url)->with('errors', $record->getErrors())->withInput();

    // Run the hydration method that populates anything else that is required / runs any other
    // model interactions and save it.
    $record->save();

    $record->networks()->sync([3,4]);

    // Redirect that shit man! You did good! Validated and saved, man mum would be proud!
    return Redirect::to($this->object_url)->with('success', new MessageBag(array('Item Created')));
}

In my repositiry I have a networks method()

public function networks()
{
    return $this->belongsToMany('Network', 'campaign_networks_relationhsips');
}

So how to extend the base eloquent to can hydrate tables?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant