public function testEloquentORM() { // Insert $article = new Article(); $article->title = static::ARTICLE_TITLE; $saved = $article->save(); $this->assertTrue($saved); $this->assertEquals(1, $article->id); $id = $article->id; // Select $article = Article::find($id); $this->assertInstanceOf('Article', $article); $this->assertEquals(static::ARTICLE_TITLE, $article->title); // Delete $deleted = Article::destroy($id); $this->assertEquals(1, $deleted); // Count $count = Article::count(); $this->assertEquals(0, $count); }
/** * Remove the specified article from storage. * * @param int $id * @return Response */ public function destroy($id) { Article::destroy($id); return Redirect::route('admin.articles.index'); }
/** * 批量操作 * @return \Illuminate\Http\JsonResponse */ public function batch() { $ids = Input::get('ids'); $action = Input::get('action'); switch ($action) { case "delete": if (count($ids) > 0) { \Article::destroy($ids); } break; default: } return Response::json(['status' => 1, 'msg' => '操作成功']); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // Article::destroy($id); }
/** * @回车站彻底删除 */ public function realDelete($ids) { //检查删除安全和正确性 $arr = explode(',', $ids); //检查删除权限,防止当前用户删除其他用户文章漏洞 foreach ($arr as $v) { if (Article::find($v)->uid != Auth::id()) { return Redirect::route('articles.recycle')->with('error', '警告!无法对未授权的文章进行危险操作!'); } } //检查删除项必须是没有分类的文章,防止非法get提交 $record = Article::whereIn("id", $arr)->sum('cid'); if ($record > 0) { return Redirect::route('articles.recycle')->with('error', '警告!检查到有非回车站中的文章进行危险操作!'); } //彻底删除对应tag Tag::whereIn('aid', $arr)->delete(); //彻底删除文章 Article::destroy($arr); //回到回车站主页 return Redirect::route('articles.recycle')->with('message', '删除成功!'); }
public function destroy($id) { Article::destroy($id); return Response::json(array('success' => true)); }
<?php require __DIR__ . '/../../vendor/autoload.php'; require '../../config.php'; require_once '../../helpers/session.php'; require '../../helpers/boot.php'; require '../../helpers/functions.php'; require_once '../../helpers/User.php'; require_once '../../helpers/Article.php'; $session = new Session(); if (!$session->getLoggedin()) { header("Location: ../../login.php"); } Article::destroy($_GET['id']); header("location: ./index.php");