/** @test */ public function it_deletes_all_specified_relations() { $user = User::create([]); $author = Author::create(['user_id' => $user->id]); $post = Post::create(['author_id' => $author->id]); $comment = Comment::create(['post_id' => $post->id]); $user = $user->fresh(); $this->assertEquals($user->author()->count(), 1, 'author'); $this->assertEquals($user->author()->first()->posts()->count(), 1, 'posts'); $this->assertEquals($user->author()->first()->posts()->first()->comments()->count(), 1, 'comments'); $user->delete(); $this->assertEquals(Post::where('author_id', 1)->count(), 0, 'post 0'); $this->assertEquals(Comment::where('post_id', 1)->count(), 0, 'comment 0'); $this->assertEquals(Author::where('user_id', 1)->count(), 0, 'user 0'); }
function createPost($postdata) { $text = htmlentities($postdata['text']); $posted_by = htmlentities($postdata['posted_by']); $date = date("Y-m-d H:i:s"); $alias = Helper::createAlias($postdata['title']); $title = htmlentities($postdata['title']); $user = new User(); $user->findByName(Session::getData('user')); $authlevel = $user->getAuthlevel(); if ($authlevel > 1) { $post = new PostModel(); $post->create($date, $title, $text, $posted_by, $alias); $post->save(); $posts = new PostModel(); $this->view->addAuthlevel($authlevel); $this->view->addPosts($posts->getAll()); $this->view->forAjax('index'); } }
public function add($parameter) { $category_slug = $parameter[0]; $this->data['title'] = 'Add Post'; $category_model = new Category(); $post_model = new \Models\Post(); $album_model = new Album(); $this->data['album_group'] = $album_model->all(); $this->data['post_category'] = $category_model->getCol('category_slug', $category_slug); // var_dump(count($this->data['post_category'])); if (isset($_POST) && !empty($_POST)) { $post_user_id = Session::get('user_id'); $post_category_id = $_POST['post_category_id']; $post_album_id = $_POST['post_album_id']; $post_title = $_POST['post_title']; $post_body = $_POST['post_body']; $post_link = $_POST['post_link']; $post_excerpt = $_POST['post_excerpt']; $post_slug = Url::generateSafeSlug($post_title); $post_created = time(); $post_array = array('post_user_id' => $post_user_id, 'post_category_id' => $post_category_id, 'post_album_id' => $post_album_id, 'post_title' => $post_title, 'post_body' => $post_body, 'post_link' => $post_link, 'post_excerpt' => $post_excerpt, 'post_slug' => $post_slug, 'post_created' => $post_created); // $insert_array = Gump::xss_clean($insert_array); // $insert_array = Gump::sanitize($insert_array); $post_id = $post_model->create($post_array); //UPLOAD IMAGE if ($_FILES["image"]["tmp_name"] != '') { Upload::setName(uniqid()); Upload::upload_file($_FILES["image"], UPLOAD_PATH); $update_data = array('post_image' => Upload::getFileName('images')); $update = $post_model->updateId($update_data, $post_id); } if ($insert_post_id > 0) { Session::set('success', 'post added'); Url::redirect('post'); } } View::rendertemplate('header', $this->data); View::rendertemplate('sidebar', $this->data); View::render('post/post.add', $this->data); View::rendertemplate('footer', $this->data); }