Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created January 14, 2013 19:58
Show Gist options
  • Save Sigmus/4532845 to your computer and use it in GitHub Desktop.
Save Sigmus/4532845 to your computer and use it in GitHub Desktop.
Generic attach m2m relationship service.
<?php
// Generic attach m2m relationship service.
Route::post('/admin/attach', function()
{
$input = Input::get();
$parent = $input['parent']['name']::find($input['parent']['id']);
$child = $input['child']['name']::find($input['child']['id']);
$parent->{Str::plural($input['child']['name'])}()->attach($child->id);
return Response::json(array('status'=>1));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment