php - RSS API 能够使用 Laravel 添加、删除和列出所有 RSS 资源
问题描述
下午好,我必须做一项原则上看起来很容易的任务。
任务是创建一个 API,允许您列出、添加和删除 RSS 源,并获取提要的最后内容。如果 RSS 源离线,我还必须找到一种方法来返回旧内容。
我已经完成了资源模型和控制器、迁移和 WEB 路由(我知道我必须将路由放在 api.php 中,但我想通过前端确保它返回我想要的所有数据,然后我将使用 Postman 对其进行测试),但我被阻止了,因为我现在不知道如何进行。
我将下面的代码留给您以了解我在做什么:
web.php(未来的 api.php):
Route::get('/', function () {
return view('welcome');
});
//Resource routes:
Route::get('/resources/{resource}', 'ResourcesController@show')
->name('resources.show');
Route::feeds();
资源控制器.php:
namespace App\Http\Controllers;
use App\Resource;
use Illuminate\Http\Request;
class ResourcesController extends Controller
{
public function show(Request $request, Resource $resource)
{
return $resource;
}
}
资源.php:
namespace App;
use Spatie\Feed\Feedable;
use Spatie\Feed\FeedItem;
use Illuminate\Database\Eloquent\Model;
class Resource extends Model implements Feedable
{
public function toFeedResource()
{
return FeedItem::create()
->id($this->id)
->title($this->title)
->content($this->description)
->updated($this->updated_at)
->link($this->link)
->source($this->source);
}
public static function getResourceItems()
{
return static::all();
}
public function getLinkAttribute()
{
return route('resources.show', $this);
}
}
create_resources_table.php:
public function up()
{
Schema::create('resources', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('description');
$table->string('source');
$table->timestamps();
});
}
欢迎任何帮助,并提前致谢。
解决方案
推荐阅读
- r - 如何根据另一个输入的值最大化 RShiny 数字输入的值?
- python - If statement throws TemplateSyntaxError Invalid block tag on line 127: 'else', expected 'empty' or 'endfor'
- ruby-on-rails - HTTP 请求在 Postman 中有效,但在 Ruby 中无效(502 错误)
- python - JSON Payload 的请求格式不熟悉
- python - “哪个”无法找到使用 pip (WSL) 安装的软件包
- mips - 继续尝试在 0x00400098 处执行非指令
- swift - 我可以在 API 的后端使用 Swift 吗?
- python - 如何保存加载的模块?
- r - maxtrix 乘法中的不一致数组错误
- r - 类似于 SQL 的条件更新