Blogger Information
Blog 41
fans 0
comment 0
visits 25313
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
后台九 文章列表
自由之上
Original
660 people have browsed it

一、数据库

1、创建 文章列表 数据表

2、填充 文章列表 数据

3、创建 文章详情 数据表

4、填充 文章详情 数据

  1. #【新建】文章表
  2. DROP TABLE IF EXISTS `article`;
  3. CREATE TABLE `article` (
  4. `id` int(10) NOT NULL AUTO_INCREMENT,
  5. `cid` int(10) NOT NULL COMMENT '文章分类',
  6. `title` varchar(255) NOT NULL COMMENT '文章标题',
  7. `thumb` varchar(255) NOT NULL DEFAULT '' COMMENT '封面图url',
  8. `subtitle` varchar(255) NOT NULL COMMENT '文章副标题',
  9. `keywords` varchar(255) NOT NULL DEFAULT '' COMMENT '文章关键字',
  10. `descs` varchar(255) NOT NULL DEFAULT '' COMMENT '文章描述',
  11. `auth_id` int(10) NOT NULL DEFAULT '0' COMMENT '作者id',
  12. `pv` int(10) NOT NULL DEFAULT '0' COMMENT '浏览量',
  13. `add_time` int(10) NOT NULL DEFAULT '0' COMMENT '添加时间',
  14. `status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态,0未发布,1发布',
  15. PRIMARY KEY (`id`),
  16. KEY `view_cid` (`cid`)
  17. ) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=utf8;
  18. #【插入】 文章表
  19. INSERT INTO `article` VALUES ('8', '0', '深圳经济特区建立40周年庆祝大会隆重举行 习近平发表重要讲话 韩正出席', '/storage/2020/10/13/nYfjV0lySqNgGHELWTP8VEkIVM0DepARyYmFQhk0.jpeg', '文章副标题', 'keywords', 'desc', '1', '0', '1602591527', '1');
  20. INSERT INTO `article` VALUES ('9', '0', '《我和我的家乡》彩蛋:群演里混了导演?这事陈凯歌、张艺谋都做过', '/storage/2020/10/13/nYfjV0lySqNgGHELWTP8VEkIVM0DepARyYmFQhk0.jpeg', '文章副标题', 'keywords', 'desc', '1', '0', '1602591586', '1');
  21. INSERT INTO `article` VALUES ('10', '0', '他们住养老院的原因 听完大家都泪目', '/storage/2020/10/13/nYfjV0lySqNgGHELWTP8VEkIVM0DepARyYmFQhk0.jpeg', '文章副标题', 'keywords', 'desc', '1', '0', '1602591694', '1');
  22. #【新建】 文章详情表
  23. DROP TABLE IF EXISTS `article_detail`;
  24. CREATE TABLE `article_detail` (
  25. `aid` int(10) NOT NULL COMMENT '文章id',
  26. `contents` text NOT NULL COMMENT '文章内容',
  27. PRIMARY KEY (`aid`)
  28. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  29. #【插入】文章详情表
  30. INSERT INTO `article_detail` VALUES ('1', '<p><strong>asdfa<span style=\"color: rgb(0, 176, 80);\">sdfa</span>sdf</strong></p><p><strong><img src=\"/ueditor/php/upload/image/20200618/1592485297674493.png\" title=\"1592485297674493.png\" alt=\"image.png\"/></strong></p>');
  31. INSERT INTO `article_detail` VALUES ('2', '<p><span style=\"background-color: rgb(192, 80, 77); color: rgb(127, 127, 127);\"><span style=\"background-color: rgb(192, 80, 77); font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;PingFang SC&quot;, 微软雅黑, Tahoma, Arial, sans-serif; font-size: 14px;\">对于刚接触web编程的同学来说,不知道哪个教程比较好,或者适合自己,php中文网今天就为同学们精选了5个html入门视频教程,全部是免费的课程,非常适合零基础学员自学,欢迎学习!</span><br/><br/><span style=\"background-color: rgb(192, 80, 77); font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;PingFang SC&quot;, 微软雅黑, Tahoma, Arial, sans-serif; font-size: 14px;\">注:html入门视频教程不提供百度云等下载,直接在线观看即可,非常方便!另外课程是按照时间倒叙排列的,无排名之分,同学们喜欢就好!</span></span><br/><br/></p>');
  32. INSERT INTO `article_detail` VALUES ('3', '&lt;p&gt;&lt;span style=&quot;background-color: rgb(192, 80, 77); color: rgb(127, 127, 127);&quot;&gt;&lt;span style=&quot;background-color: rgb(192, 80, 77); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;PingFang SC&amp;quot;, 微软雅黑, Tahoma, Arial, sans-serif; font-size: 14px;&quot;&gt;对于刚接触web编程的同学来说,不知道哪个教程比较好,或者适合自己,php中文网今天就为同学们精选了5个html入门视频教程,全部是免费的课程,非常适合零基础学员自学,欢迎学习!&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;&lt;span style=&quot;background-color: rgb(192, 80, 77); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;PingFang SC&amp;quot;, 微软雅黑, Tahoma, Arial, sans-serif; font-size: 14px;&quot;&gt;注:html入门视频教程不提供百度云等下载,直接在线观看即可,非常方便!另外课程是按照时间倒叙排列的,无排名之分,同学们喜欢就好!&lt;/span&gt;&lt;/span&gt;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;');

二、文章列表 模块

1、创建 文章列表 视图模板

2、编辑 文章列表 视图模板


resources/views/admins/article/index.blade.php

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>文章列表</title>
  5. <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/layui/layui.js"></script>
  7. </head>
  8. <body style="padding: 10px;">
  9. <div style="text-align: right;">
  10. <button class="layui-btn layui-btn-sm" onclick="add()"><i class="layui-icon layui-icon-addition"></i>添加</button>
  11. </div>
  12. <table class="layui-table" style="min-width: 800px">
  13. <thead>
  14. <tr>
  15. <th>ID</th>
  16. <th>文章分类</th>
  17. <th>文章标题</th>
  18. <th>文章缩略图</th>
  19. <th>文章作者</th>
  20. <th>PV</th>
  21. <th>状态</th>
  22. <th>添加时间</th>
  23. <th style="width: 90px">操作</th>
  24. </tr>
  25. </thead>
  26. <tbody>
  27. @foreach($data as $val)
  28. <tr>
  29. <td>{{$val['id']}}</td>
  30. <td>{{isset($cates[$val['cid']])?$cates[$val['cid']]['title']:''}}</td>
  31. <td style="width: 90px">{{$val['title']}}</td>
  32. <td><img src="{{$val['thumb']}}" style="height: 30px;"></td>
  33. <td>{{isset($auths[$val['auth_id']])?$auths[$val['auth_id']]['username']:''}}</td>
  34. <td>{{$val['pv']}}</td>
  35. <td>{{$val['status']==0?'草稿':'已发布'}}</td>
  36. <td>{{date('Y-m-d H:i:s',$val['add_time'])}}</td>
  37. <td style="width: 90px">
  38. <button class="layui-btn layui-btn-xs" onclick="edit({{$val['id']}})">修改</button>
  39. <button class="layui-btn layui-btn-xs layui-btn-danger" onclick="del({{$val['id']}})">删除</button>
  40. </td>
  41. </tr>
  42. @endforeach
  43. </tbody>
  44. </table>
  45. <div id="pages" style="text-align: center"></div>
  46. </body>
  47. </html>
  48. <script type="text/javascript">
  49. layui.use(['layer', 'laypage'], function () {
  50. $ = layui.jquery;
  51. layer = layui.layer;
  52. var laypage = layui.laypage;
  53. laypage.render({
  54. elem: 'pages'
  55. , curr:{{$page}}
  56. , limit:{{$pageSize}}
  57. , count: {{$total}}
  58. , jump: function (obj, first) {
  59. //首次不执行
  60. if (!first) {
  61. window.location.href = '/admins/article/index?page=' + obj.curr;
  62. }
  63. }
  64. });
  65. });
  66. // 添加文章
  67. function add() {
  68. layer.open({
  69. type: 2,
  70. title: '添加文章',
  71. shade: 0.3,
  72. area: ['750px', '750px'],
  73. content: '/admins/article/add'
  74. });
  75. }
  76. // 修改文章
  77. function edit(id) {
  78. layer.open({
  79. type: 2,
  80. title: '修改文章',
  81. shade: 0.3,
  82. area: ['750px', '750px'],
  83. content: '/admins/article/edit?id=' + id
  84. });
  85. }
  86. // 删除
  87. function del(id) {
  88. layer.confirm('确定要删除吗?', {
  89. icon: 3,
  90. btn: ['确定', '取消']
  91. }, function () {
  92. $.get('/admins/article/del', {id: id}, function (res) {
  93. if (res.code > 0) {
  94. return layer.alert(res.msg, {icon: 2});
  95. }
  96. layer.msg(res.msg);
  97. setTimeout(function () {
  98. window.location.reload();
  99. }, 1000);
  100. }, 'json');
  101. });
  102. }
  103. </script>

3、文章列表 控制器处理

app/Http/Controllers/admins/Article.php

  1. // 文章列表
  2. public function index(Request $req) {
  3. $data['page'] = max(1, (int)$req->page);
  4. $data['pageSize'] = 10;
  5. $pageObj = DB::table('article')->orderBy('id', 'desc')->paginate($data['pageSize']);
  6. $data['total'] = $pageObj->total();
  7. $data['data'] = $pageObj->items();
  8. $data['data'] = array_map(function ($val) { return (array)$val; }, $data['data']);
  9. // 文章分类
  10. $data['cates'] = DB::table('article_cate')->cates('id');
  11. // 文章作者
  12. $data['auths'] = DB::table('admin')->cates('id');
  13. return view('/admins/article/index', $data);
  14. }

4、文章列表 路由注册

  1. //显示文章列表
  2. Route::get('/admins/article/index', [Article::class, 'index']);

" class="reference-link">

5、查看效果

三、上传文件 模块

1、创建 上传文件 控制器

2、编辑 上传文件 控制器

app/Http/Controllers/admins/Files.php

  1. <?php
  2. namespace App\Http\Controllers\admins;
  3. use App\Http\Controllers\Controller;
  4. /**
  5. * 上传文件 控制器
  6. * @package App\Http\Controllers\admins
  7. */
  8. class Files extends Controller {
  9. }

3、上传文件 控制器处理

  1. use Illuminate\Http\Request;
  2. use Illuminate\Support\Facades\Storage;
  3. // 图片上传-中间不要随意向前端传递数据,会导致请求上传接口出现异常问题
  4. public function uploadimg(Request $request) {
  5. $path = $request->file('file')->store('public/article/' . date('Y/m/d'));
  6. $url = Storage::url($path);
  7. // 把路径保存到数据库中,同时加状态,初始状态为0(表示草稿状态),1(表示正常使用状态)
  8. return json_encode(array('code' => 0, 'msg' => '', 'data' => array('src' => $url)));
  9. }

4、注册软链接

参考:Laravel 图片不显示解决方案
1、在项目目录下执行命令创建软链接

  1. php artisan storage:link

5、上传文件 路由注册

  1. // 文件上传相关
  2. Route::post('/admins/files/uploadimg',[Files::class, 'uploadimg']);

四、富文本编辑器 模块

1、下载附件

ueditor.zip

2、解压附件内容

3、将附件中ueditor文件拷贝到项目public 下的 statci目录下

五、添加并保存文章 模块

1、创建 添加并保存文章 模板视图

2、编辑 添加并保存文章 模板视图


resources/views/admins/article/add.blade.php

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>添加文章</title>
  5. <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/layui/layui.js"></script>
  7. <script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
  8. <script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>
  9. </head>
  10. <body style="padding: 10px;">
  11. <div class="layui-form">
  12. @csrf
  13. <div class="layui-form-item">
  14. <label class="layui-form-label">文章标题</label>
  15. <div class="layui-input-block">
  16. <input type="text" class="layui-input" name="title">
  17. </div>
  18. </div>
  19. <div class="layui-form-item">
  20. <label class="layui-form-label">文章副标题</label>
  21. <div class="layui-input-block">
  22. <input type="text" class="layui-input" name="subtitle">
  23. </div>
  24. </div>
  25. <div class="layui-form-item">
  26. <label class="layui-form-label">文章分类</label>
  27. <div class="layui-input-block">
  28. <select name="cid">
  29. @foreach($cates as $val)
  30. <option value="{{$val['id']}}">{{$val['title']}}</option>
  31. @endforeach
  32. </select>
  33. </div>
  34. </div>
  35. <div class="layui-form-item">
  36. <label class="layui-form-label">缩略图</label>
  37. <div class="layui-input-block">
  38. <button class="layui-btn" id="uploadimg"><i class="layui-icon">&#xe67c;</i>上传图片</button>
  39. <img id="preimg" src="" style="height: 30px;">
  40. </div>
  41. </div>
  42. <div class="layui-form-item">
  43. <label class="layui-form-label">关键字</label>
  44. <div class="layui-input-block">
  45. <input type="text" class="layui-input" name="keywords">
  46. </div>
  47. </div>
  48. <div class="layui-form-item">
  49. <label class="layui-form-label">描述</label>
  50. <div class="layui-input-block">
  51. <input type="text" class="layui-input" name="descs">
  52. </div>
  53. </div>
  54. <div class="layui-form-item">
  55. <label class="layui-form-label">文章内容</label>
  56. <div class="layui-input-block">
  57. <script id="container" name="content" type="text/plain"></script>
  58. </div>
  59. </div>
  60. <div class="layui-form-item">
  61. <label class="layui-form-label">状态</label>
  62. <div class="layui-input-block">
  63. <input type="checkbox" name="status" lay-skin="primary" title="发布">
  64. </div>
  65. </div>
  66. <div class="layui-input-block">
  67. <button class="layui-btn" onclick="save()">保存</button>
  68. </div>
  69. </div>
  70. </body>
  71. </html>
  72. <script type="text/javascript">
  73. layui.use(['upload','form','layer'],function(){
  74. $ = layui.jquery;
  75. layer = layui.layer;
  76. form = layui.form;
  77. var upload = layui.upload;
  78. upload.render({
  79. elem: '#uploadimg'
  80. ,url: '/admins/files/uploadimg'
  81. ,data: {
  82. _token: function(){
  83. return $('input[name="_token"]').val();
  84. }
  85. }
  86. ,done: function(res){
  87. console.log("图片上传2:",res);
  88. if(res.code>0){
  89. return layer.alert(res.msg,{icon:2});
  90. }
  91. $('#preimg').attr('src',res.data.src);
  92. }
  93. });
  94. });
  95. // 保存
  96. function save(){
  97. var data = {};
  98. data.title = $('input[name="title"]').val();
  99. data.subtitle = $('input[name="subtitle"]').val();
  100. data.cid = $('select[name="cid"]').val();
  101. data.thumb = $('#preimg').attr('src');
  102. data.keywords = $('input[name="keywords"]').val();
  103. data.descs = $('input[name="descs"]').val();
  104. data.contents = ue.getContent();
  105. data.status = $('input[name="status"]').is(':checked')?1:0;
  106. data._token = $('input[name="_token"]').val();
  107. if(data.title==''){
  108. return layer.alert('请输入文章标题',{icon:2});
  109. }
  110. $.post('/admins/article/save',data,function(res){
  111. if(res.code>0){
  112. return layer.alert(res.msg,{icon:2});
  113. }
  114. layer.msg(res.msg);
  115. setTimeout(function(){parent.window.location.reload();},1000);
  116. },'json');
  117. }
  118. </script>
  119. <script type="text/javascript">
  120. var ue = UE.getEditor('container',{initialFrameWidth:'100%',initialFrameHeight:500,zIndex:1});
  121. </script>

3、添加并保存文章 控制器处理

  1. // 添加文章
  2. public function add() {
  3. $data['cates'] = DB::table('article_cate')->lists();
  4. return view('/admins/article/add', $data);
  5. }
  6. // 保存文章
  7. public function save(Request $req) {
  8. $data['title'] = trim($req->title);
  9. $data['subtitle'] = trim($req->subtitle);
  10. $data['cid'] = (int)$req->cid;
  11. $data['thumb'] = trim($req->thumb);
  12. $data['keywords'] = trim($req->keywords);
  13. $data['descs'] = trim($req->descs);
  14. $data['auth_id'] = $req->admin->id;
  15. $data['status'] = (int)$req->status;
  16. $data['add_time'] = time();
  17. $contents = trim($req->contents);
  18. $code = 1;
  19. $msg = '保存失败';
  20. // 数据写入数据库(持久化)
  21. $aid = DB::table('article')->insertGetId($data);
  22. if ($aid) {
  23. $res = DB::table('article_detail')->insert(['aid' => $aid, 'contents' => $contents]);
  24. if ($res) {
  25. $code = 0;
  26. $msg = '保存成功';
  27. }
  28. }
  29. return json_encode(array('code' => $code, 'msg' => $msg));
  30. }

4、添加并保存 注册路由

  1. //添加文章弹窗
  2. Route::get('/admins/article/add',[Article::class, 'add']);
  3. //保存文章处理
  4. Route::post('/admins/article/save',[Article::class, 'save']);

5、查看效果

六、编辑与保存编辑文章 模块

1、创建 编辑与保存编辑 视图模板

2、编辑 编辑与保存编辑 视图模板


resources/views/admins/article/edit.blade.php

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>修改文章</title>
  5. <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
  6. <script type="text/javascript" src="/static/layui/layui.js"></script>
  7. <script type="text/javascript" src="/static/ueditor/ueditor.config.js"></script>
  8. <script type="text/javascript" src="/static/ueditor/ueditor.all.js"></script>
  9. </head>
  10. <body style="padding: 10px;">
  11. <div class="layui-form">
  12. @csrf
  13. <input type="hidden" name="aid" value="{{$item['id']}}">
  14. <div class="layui-form-item">
  15. <label class="layui-form-label">文章标题</label>
  16. <div class="layui-input-block">
  17. <input type="text" class="layui-input" name="title" value="{{$item['title']}}">
  18. </div>
  19. </div>
  20. <div class="layui-form-item">
  21. <label class="layui-form-label">文章副标题</label>
  22. <div class="layui-input-block">
  23. <input type="text" class="layui-input" name="subtitle" value="{{$item['subtitle']}}">
  24. </div>
  25. </div>
  26. <div class="layui-form-item">
  27. <label class="layui-form-label">文章分类</label>
  28. <div class="layui-input-block">
  29. <select name="cid">
  30. @foreach($cates as $val)
  31. <option value="{{$val['id']}}" {{$item['cid']==$val['id']?'selected':''}}>{{$val['title']}}</option>
  32. @endforeach
  33. </select>
  34. </div>
  35. </div>
  36. <div class="layui-form-item">
  37. <label class="layui-form-label">缩略图</label>
  38. <div class="layui-input-block">
  39. <button class="layui-btn" id="uploadimg"><i class="layui-icon">&#xe67c;</i>上传图片</button>
  40. <img id="preimg" src="{{$item['thumb']}}" style="height: 30px;">
  41. </div>
  42. </div>
  43. <div class="layui-form-item">
  44. <label class="layui-form-label">关键字</label>
  45. <div class="layui-input-block">
  46. <input type="text" class="layui-input" name="keywords" value="{{$item['keywords']}}">
  47. </div>
  48. </div>
  49. <div class="layui-form-item">
  50. <label class="layui-form-label">描述</label>
  51. <div class="layui-input-block">
  52. <input type="text" class="layui-input" name="descs" value="{{$item['descs']}}">
  53. </div>
  54. </div>
  55. <div class="layui-form-item">
  56. <label class="layui-form-label">文章内容</label>
  57. <div class="layui-input-block">
  58. <script id="container" name="content" type="text/plain">{!!$detail['contents']!!}</script>
  59. </div>
  60. </div>
  61. <div class="layui-form-item">
  62. <label class="layui-form-label">状态</label>
  63. <div class="layui-input-block">
  64. <input type="checkbox" name="status" lay-skin="primary" title="发布" {{$item['status']==1?'checked':''}}>
  65. </div>
  66. </div>
  67. <div class="layui-input-block">
  68. <button class="layui-btn" onclick="save()">保存</button>
  69. </div>
  70. </div>
  71. </body>
  72. </html>
  73. <script type="text/javascript">
  74. layui.use(['upload','form','layer'],function(){
  75. $ = layui.jquery;
  76. layer = layui.layer;
  77. form = layui.form;
  78. var upload = layui.upload;
  79. upload.render({
  80. elem: '#uploadimg'
  81. ,url: '/admins/files/uploadimg'
  82. ,data: {
  83. _token: function(){
  84. return $('input[name="_token"]').val();
  85. }
  86. }
  87. ,done: function(res){
  88. $('#preimg').attr('src',res.data.src);
  89. }
  90. });
  91. });
  92. // 保存
  93. function save(){
  94. var data = {};
  95. data.aid = $('input[name="aid"]').val();
  96. data.title = $('input[name="title"]').val();
  97. data.subtitle = $('input[name="subtitle"]').val();
  98. data.cid = $('select[name="cid"]').val();
  99. data.thumb = $('#preimg').attr('src');
  100. data.keywords = $('input[name="keywords"]').val();
  101. data.descs = $('input[name="descs"]').val();
  102. data.contents = ue.getContent();
  103. data.status = $('input[name="status"]').is(':checked')?1:0;
  104. data._token = $('input[name="_token"]').val();
  105. if(data.title==''){
  106. return layer.alert('请输入文章标题',{icon:2});
  107. }
  108. console.log("保存文章编辑")
  109. $.post('/admins/article/save_edit',data,function(res){
  110. if(res.code>0){
  111. return layer.alert(res.msg,{icon:2});
  112. }
  113. layer.msg(res.msg);
  114. setTimeout(function(){parent.window.location.reload();},1000);
  115. },'json');
  116. }
  117. </script>
  118. <script type="text/javascript">
  119. var ue = UE.getEditor('container',{initialFrameWidth:'100%',initialFrameHeight:500,zIndex:1});
  120. </script>

3、编辑与保存编辑 控制器处理

app/Http/Controllers/admins/Article.php

  1. // 修改文章
  2. public function edit(Request $req) {
  3. $id = (int)$req->id;
  4. $data['item'] = DB::table('article')->where('id', $id)->item();
  5. $data['detail'] = DB::table('article_detail')->where('aid', $id)->item();
  6. $data['cates'] = DB::table('article_cate')->lists();
  7. return view('admins/article/edit', $data);
  8. }
  9. // 保存修改
  10. public function save_edit(Request $req) {
  11. $aid = (int)$req->aid;
  12. $data['title'] = trim($req->title);
  13. $data['subtitle'] = trim($req->subtitle);
  14. $data['cid'] = (int)$req->cid;
  15. $data['thumb'] = trim($req->thumb);
  16. $data['keywords'] = trim($req->keywords);
  17. $data['descs'] = trim($req->descs);
  18. $data['auth_id'] = $req->admin->id;
  19. $data['status'] = (int)$req->status;
  20. $data['add_time'] = time();
  21. $this->contents = trim($req->contents);
  22. $this->aid = $aid;
  23. $this->data = $data;
  24. // 数据写入数据库(持久化)
  25. DB::transaction(function () {
  26. DB::table('article')->where('id', $this->aid)->update($this->data);
  27. DB::table('article_detail')->where('aid', $this->aid)->update(['contents' => $this->contents]);
  28. });
  29. return json_encode(array('code' => 0, 'msg' => '保存成功'));
  30. }

4、编辑与保存编辑 路由注册

routes/web.php

  1. //编辑文章弹窗
  2. Route::get('/admins/article/edit',[Article::class, 'edit']);
  3. //保存编辑文章处理
  4. Route::post('/admins/article/save_edit',[Article::class, 'save_edit']);

5、查看效果

七、删除文章 模块

1、删除文章 控制器处理

  1. // 删除文章
  2. public function del(Request $req) {
  3. $aid = (int)$req->id;
  4. DB::table('article')->where('id', $aid)->delete();
  5. DB::table('article_detail')->where('aid', $aid)->delete();
  6. return json_encode(array('code' => 0, 'msg' => '删除成功'));
  7. }

2、删除文章 注册路由

  1. //删除文章处理
  2. Route::get('/admins/article/del',[Article::class, 'del']);

3、查看效果

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post