laravel-bootstrap
laravel-bootstrap copied to clipboard
Many to Many relation how to override?
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?