6.2. 发布话题
发布话题
参考下面这个发布话题的界面:
需要填写话题标题,话题内容,选择话题分类。如果这个话题内容,可以上传图片,插入 markdown 图片链接,则可以调用我们上一节写的 添加图片
接口,type 为 topic,将返回的图片 path 插入到话题内容中。
1. 增加路由
只有登录用户才可以发布话题,添加路由。
routes/api.php
.
.
.
// 图片资源
$api->post('images', 'ImagesController@store')
->name('api.images.store');
// 发布话题
$api->post('topics', 'TopicsController@store')
->name('api.topics.store');
.
.
.
2. 增加 Request
创建 TopicRequest:
$ php artisan make:request Api/TopicRequest
如下修改:
app/Http/Requests/Api/TopicRequest.php
<?php
namespace App\Http\Requests\Api;...