💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 第6节 构建 Article 后台管理功能 ### 6.1 添加路由 *D:\wamp\www\newblog.com\app\Http\routes.php* ~~~ Route::group(['middleware' => 'auth', 'namespace' => 'Admin', 'prefix' => 'admin'], function() { Route::get('/', 'HomeController@index'); Route::get('article', 'ArticleController@index'); }); ~~~ #### 添加控制器 ~~~ php artisan make:controller Admin/ArticleController ~~~ #### 新添index方法 *D:\wamp\www\newblog.com\app\Http\Controllers\Admin\ArticleController.php* ~~~ <?php namespace App\Http\Controllers\Admin; use App\Models\Article; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; class ArticleController extends Controller { public function index() { return view('admin/article/index')->withArticles(Article::all()); } } ~~~ 注意:引入Article类 ~~~ use App\Models\Article; ~~~ #### 新建视图 *D:\wamp\www\newblog.com\resources\views\admin\article\index.blade.php* ~~~ @extends('layouts.app') @section('content') <div class="container"> <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading">文章管理</div> <div class="panel-body"> @if (count($errors) > 0) <div class="alert alert-danger"> {!! implode('<br>', $errors->all()) !!} </div> @endif <a href="{{ url('admin/article/create') }}" class="btn btn-lg btn-primary">新增</a> @foreach ($articles as $article) <hr> <div class="article"> <h4>{{ $article->title }}</h4> <div class="content"> <p> {{ $article->body }} </p> </div> </div> <a href="{{ url('admin/article/'.$article->id.'/edit') }}" class="btn btn-success">编辑</a> <form action="{{ url('admin/article/'.$article->id) }}" method="POST" style="display: inline;"> {{ method_field('DELETE') }} {{ csrf_field() }} <button type="submit" class="btn btn-danger">删除</button> </form> @endforeach </div> </div> </div> </div> </div> @endsection ~~~ 访问:`http://newblog.com/admin/article` 查看效果 ![](https://box.kancloud.cn/5f9aeec552a24ee9a4828b59c5598fc0_943x728.png) OK! 下一章节,我们来继续实现删除,编辑,修改操作吧!