Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.controller('NewPostController', function($scope, $http) {
- $scope.selection = [];
- $http.get('/new_post').success(function(tags) {
- $scope.tags = tags;
- });
- $scope.toggleSelection = function toggleSelection(tag) {
- var idx = $scope.selection.indexOf(tag);
- // is currently selected
- if (idx > -1) {
- $scope.selection.splice(idx, 1);
- }
- // is newly selected
- else {
- $scope.selection.push(tag);
- }
- };
- $scope.addPost = function() {
- $scope.post.selection = $scope.selection;
- $http.post('new_post', $scope.post).success(function() {
- });
- }
- class PostController extends BaseController {
- public function add() {
- if($post = Post::insertGetId(array('title' => Input::json('title'),
- 'body' => Input::json('body')))) {
- $tags = [];
- foreach(Input::json('selection') as $tag) {
- array_push($tags, $tag['id']);
- }
- $new_post = Post::find($post);
- $new_post->tags()->sync($tags);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement